GlPolygonMode (GL_FRONT_AND_BACK, GL_LINES) does not work

I am trying to display primitives in normal fill mode and then as a wired frame.

Visualization Code:

glClear(GL_COLOR_BUFFER_BIT); glClearColor(0.9f, 0.9f, 0.9f, 1); // reset matrix glLoadIdentity(); // fill display list glColor3c(150, 255, 255); glCallList(lDList); // wireframe display list glColor3f(0, 0, 0); glLineWidth(10); glPolygonMode(GL_FRONT_AND_BACK, GL_LINES); glCallList(lDList); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 

Display list creation code:

 lDList = glGenLists(1); glNewList(lDList, GL_COMPILE); glBegin(GL_QUADS); glVertex3i(-1, -1, 0); glVertex3i(1, -1, 0); glVertex3i(1, -1, -25); glVertex3i(-1, -1, -25); glEnd(); glEndList(); 

glColor3c Macro:

 #define glColor3c(r, g, b) glColor3f(r / 255, g / 255, b / 255) 

I expect to get a bluish color plane drawn with a black frame around it, but all that happens is that the second time I present a display list, it just fills and draws the whole thing, overwriting the pixels for another primitive. I end up with the plane that I want to draw, but its just black (the color that I specified for the string "version").

Any other information that may be helpful is that I use SDL on Windows 7 with MSVC ++ 2010. I don't call glEnable, so I don’t have any weird settings that could ruin or possibly solve the problem . My only OpenGL installation code sets up the forecast matrix and model matrix, and then creates a display list.

Obviously, my question is: why the second time I draw a display list, does it populate the primitive instead of creating lines? How to fix it?

+4
source share
1 answer

According to the docs for glPolygonMode in OpenGL 4.0, the second argument to mode can only be one of GL_FILL , GL_POINT or GL_LINE . In your example, you pass GL_LINES , which is a completely different enum value.

I suspect that the GL_LINES transmission is handled by OpenGL in such a way that by default it returns to GL_FILL if the received mode is not as expected.

Also note: the specification for glPolygonMode same as the specification for OpenGL 2.1.

+10
source

Source: https://habr.com/ru/post/1444498/


All Articles