How to render perfect wireframed rectangle in 2D mode with OpenGL?

后端 未结 4 1061
离开以前
离开以前 2020-12-30 03:08

Edit: just so you know: I have not solved this problem perfectly yet, currently I am using 0.5px offset, it seems to work, but as others have said,

4条回答
  •  灰色年华
    2020-12-30 04:12

    This is not a bug, this is exactly following the specification. The last pixel of a line is not drawn to prevent overdraw with following line segments, which would cause problems with blending. Solution: Send the last vertex twice.

    Code Update

    // don't use glPolygonMode, it doesn't
    // do what you think it does
    glBegin(GL_LINE_STRIP);
        glVertex2f(a);
        glVertex2f(b);
        glVertex2f(c);
        glVertex2f(d);
        glVertex2f(a);
        glVertex2f(a); // resend last vertex another time, to close the loop
    glEnd();
    

    BTW: You should learn how to use vertex arrays. Immediate mode (glBegin, glEnd, glVertex calls) have been removed from OpenGL-3.x core and onward.

提交回复
热议问题