Render an outlined red rectangle on top a 2D texture in OpenGL

前端 未结 1 1156
终归单人心
终归单人心 2021-01-24 02:16

I have searched alot this site but couldn\'t exactly find what is exactly my problem. Most of the similar problems had used console and the glut library. But since I\'m new to O

相关标签:
1条回答
  • 2021-01-24 02:57

    Since edge flags are deprecated in modern OpenGL, I would avoid using a polygon fill mode to draw the outlines. If I understand your screenshot correctly, you are getting lines on the interior edges of the two triangles used to draw your rectangle.

    Instead draw a red GL_LINE_LOOP that uses the 4 corners of your rectangle... this is the preferred technique for portability reasons, since GL_QUADS are also deprecated.

    glColor3f     (1.0f, 0.0f, 0.0f);
    glBegin       (GL_LINE_LOOP);
       glVertex3f (RectangleToDraw.at (0), RectangleToDraw.at (1), -1.0f);
       glVertex3f (RectangleToDraw.at (0), RectangleToDraw.at (3), -1.0f);
       glVertex3f (RectangleToDraw.at (2), RectangleToDraw.at (3), -1.0f);
       glVertex3f (RectangleToDraw.at (2), RectangleToDraw.at (1), -1.0f);
    glEnd         ();
    

    Also, your screenshot appears to be suffering from attempting to texture the outline. Disable GL_TEXTURE_2D before you draw your lines.

    0 讨论(0)
提交回复
热议问题