Reputation: 406
I am encountering a very weird issue in OpenGl. The following code produces a yellow cube as expected
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (GLfloat[]){ 1, 1, 0, 1 });
glBegin(GL_LINE_LOOP);
glutSolidCube(1);
glPopMatrix();
glEnd();
However when I put glpopMatrix() after glEnd(), I just get a black screen without a cube.
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (GLfloat[]){ 1, 1, 0, 1 });
glBegin(GL_LINE_LOOP);
glutSolidCube(1);
glEnd();
glPopMatrix();
To me the second approach makes more sense, (push, begin, end then pop) and I really have no idea why it does not work. Any help is appreciated, thanks!
Upvotes: 0
Views: 30
Reputation: 26207
The problem is not the placement of the glPopMatrix()
call. The problem is with glBegin()
and glEnd()
. Remove them, glutSolidCube()
does that already.
If you're using FreeGLUT then glutSolidCube()
won't even be using glBegin()
and glEnd()
, and will be using vertex arrays under the hood. So to put it simply, you're probably just confusing your driver and that's why you're getting the weird result.
Upvotes: 2