Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: How to demonstrate a T-junction problem with OpenGL

  1. #1
    Newbie Newbie
    Join Date
    Feb 2014
    Posts
    2

    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:

    Code :
    glColor3f(1.0f, 0.0f, 0.0f);//red
    		for(int i=-50; i<50; i+=10)
    		{
    			glBegin(GL_QUADS);
    			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);
    			glEnd();
    		}
     
    		glColor3f(0.0f, 1.0f, 0.0f);//green
    		for(int i=-50; i<50; i+=6)
    		{
    			glBegin(GL_QUADS);
    			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);
    			glEnd();
    		}
    The first row rectangles are 10*20 with normal vector (-1, 0, 1) and second row rectangles are 6*20 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!!!

  2. #2
    Newbie Newbie
    Join Date
    Feb 2014
    Posts
    2
    It seems like I'm not able to upload picture result. Hope anyone could understand what I mean

  3. #3
    Intern Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Location
    Aachen / Germany
    Posts
    71
    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

    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?

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,224
    Yes, you have T-junctions:

    Code :
                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.

    Code :
    *
    | \
    |  \
    |   \
    |    \
    |     \
    |      \
    |       \
    |        \
    *---------T--*
    |           /
    |          /
    |         /
    |        /
    |       /
    |      /
    |     /
    |    /
    |   /
    |  /
    | /
    *

    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.
    Last edited by Dark Photon; 02-07-2014 at 06:59 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •