How to demonstrate a T-junction problem with OpenGL

Hi All:

I’m working on demonstrate the classic T-junction problem. So I create several rectangles in two rows like this:

glColor3f(1.0f, 0.0f, 0.0f);//red
		for(int i=-50; i<50; i+=10)
			glNormal3f(-1, 0,1);
			glVertex3f(i, 20.0f, 0.0f);
			glNormal3f(-1, 0,1);
			glVertex3f(i+10, 20.0f, 0.0f);
			glNormal3f(-1, 0,1);
			glVertex3f(i+10, 0.0f, 0.0f);
			glNormal3f(-1, 0, 1);
			glVertex3f(i, 0.0f, 0.0f);

		glColor3f(0.0f, 1.0f, 0.0f);//green
		for(int i=-50; i<50; i+=6)
			glNormal3f(0, 0, 1);
			glVertex3f(i, 0.0f, 0.0f);
			glNormal3f(0, 0, 1);
			glVertex3f(i+6, 0.0f, 0.0f);
			glNormal3f(0, 0, 1);
			glVertex3f(i+6, -20.0f, 0.0f);
			glNormal3f(0, 0, 1);
			glVertex3f(i, -20.0f, 0.0f);

The first row rectangles are 1020 with normal vector (-1, 0, 1) and second row rectangles are 620 with normal vector (0, 0, 1). They share edges but vertices are not in the same coordinate. And I put the camera on (0, 0, 80) and a light on (0,0,10). Then I rotate it, I found some zig-zag between the red and greed edges, is it a T-junction artifact? I’m not sure, if not, please give me some hints about how to create the T-junction artifact. Thanks!!!

It seems like I’m not able to upload picture result. Hope anyone could understand what I mean

It seems in this forum, you can only link external sources after you made some posts. I couldn’t do so in my first post either :wink:

I printed your coordinates and can find nothing suspicious, apart from the face normal:

  1. You don’t need to set it before every vertex. It stays as long as no new normal is set.
  2. It should be orthogonal to your triangle, and in the first loop, it clearly isn’t. But this is not likely to be the problem you are looking for.
    If you want, you can send me a screenshot via PN and I’ll include it here.

Anyway, these effects can happen: If faces touch each others’ edges very precisely, the depth testing is sometimes not accurate enough to determine which is in front of the other (z-fighting). But did I understand you correctly, you want to create these artefacts on purpose?

Yes, you have T-junctions:

            glVertex3f(i   , 20, 0);
            glVertex3f(i+10, 20, 0);
            glVertex3f(i+10,  0, 0);
            glVertex3f(i   ,  0, 0);

            glVertex3f(i  ,   0, 0);
            glVertex3f(i+6,   0, 0);
            glVertex3f(i+6, -20, 0);
            glVertex3f(i  , -20, 0);

Notice that your stride for the top (red) is x=+10, while the stride for the bottom (green) is x=+6.

A T-junction occurs when you have a triangle vertex occurring in the middle of the edge of another. For instance, below “T” is the vertex that causes a T-junction.

| \
|  \
|   \
|    \
|     \
|      \
|       \
|        \
|           /
|          /
|         /
|        /
|       /
|      /
|     /
|    /
|   /
|  /
| /

The problem with T-junctions is that due to precision issues, the vertex on the edge is not exactly on the edge, and depending on the computation that’s done, you can end up with stray pixels or samples between the two triangles that don’t actually get coverage (i.e. aren’t filled, or are filled twice).

Also re the posting images issue… Yes, new users aren’t allowed to post images until they’ve posted a few times – this is to cut down on spam. Just put some spaces in the URL or something to get it posted and we’ll fix it up for you.