开发者

Drawing connected lines with OpenGL [duplicate]

This question already has an answer here: Make openGL lines connected (1 answer) 开发者_JAVA百科 Closed 9 years ago.

I'm drawing convex polygons with OpenGL. I then do the same thing but use GL_LINE_LOOP. The problem I have is the lines are not always connected. How could I ensure that the lines are always connected?

In the photo below, Iv highlighted in green, the corners that are connected and in red, those that are not. I would like for them to be all like the green ones.

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


What you're looking for is called endpoint capping / mitering. OpenGL doesn't support this natively, see 14.100

Using wide lines (line width 50) amplifies the problem. You might want to try using OpenGL tesselation. This example might seem a bit much, but I think there is some valuable interfacing between Java2D shapes and OpenGL tesselation that might fix your problem at the cost of some rewriting / rethinking.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜