Drawing connected lines with OpenGL

I am drawing convex polygons with OpenGL. Then I do the same thing but use GL_LINE_LOOP. The problem is that the lines aren't always connected. How can I ensure that the lines are always connected?

In the photo below, Iv is highlighted in green, the corners that are connected and blush and those that are not. I would like them to look like green.

http://img249.imageshack.us/i/notconnected.png/

thanks

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
x ++;
glLineWidth(50.0);

glPushMatrix();
glTranslatef(250,250,0);
    glBegin(GL_POLYGON); //Begin quadrilateral coordinates

    //Trapezoid
    glColor3f(255,0,0);
glVertex2f(-10,0);
glVertex2f(50,0);
glColor3f(255,100,0);
glVertex2f(100,50);
glVertex2f(mouse.x - 250,mouse.y - 250);
glVertex2f(-30,50);

    glEnd(); //End quadrilateral coordinates

    glBegin(GL_LINE_LOOP); //Begin quadrilateral coordinates

    //Trapezoid
    glColor3f(0,0,255);
    glVertex2f(-10,0);
    glVertex2f(50,0);

    glVertex2f(100,50);
    glVertex2f(mouse.x - 250,mouse.y - 250);
    glVertex2f(-30,50);

    glEnd(); //End quadrilateral coordinates

    glPopMatrix();
    glBegin(GL_QUADS); //Begin quadrilateral coordinates

    glVertex2f(0,0);
glColor3f(0,255,0);
    glVertex2f(150,0);
    glVertex2f(150,150);
    glColor3f(255,0,0);
    glVertex2f(0,150);


    glEnd(); //End quadrilateral coordinates

      

+2


a source to share


1 answer


What you are looking for is called endpoints closing / shrinking. OpenGL does not natively support this , see 14.100



Using wide lines (line width 50) exacerbates the problem. You might want to try using OpenGL tagging . This example may sound a bit big, but I think there is some valuable relationship between Java2D forms and OpenGL tagging that might solve your problem with some rewriting / rethinking.

+2


a source







All Articles