PDA

View Full Version : resetting openGL state



Ranjith
03-19-2009, 03:40 AM
I am using openGL instructions in vega prime for drawing.

I am using the following code.
_____________________________________________
//storing the current attribute values
glPushAttrib(GL_ALL_ATTRIB_BITS);

glColor4f(-,-,-,-);
glPolygonMode(GL_FRONT,GL_FILL);
glInterleavedArrays(GL_T2F_V3F,0,someQuad);
glDrawArrays(GL_QUADS,0,4);

//restoring old attribute values
glPopAttrib();
_____________________________________________

But the graphics are not resetting to its previous values(eg. sky color is changed when drawing). But after completion of whole openGL drawing, the vega prime scene is resetting to its previous value(even with out resetting the old attribute values). But I want the remain scene in its original state while drawing. How can I do that? (i.e. the background scene should not change while drawing with openGL functions).

Relic
03-19-2009, 04:23 AM
Sounds more like a driver bug when ALL_ATTRIB_BITS is not restoring the color which is pushed with CURRENT_BITS.
What OpenGL implementation are you running? (graphics board, driver version)

If all you change is glColor and glPolygonMode, it would be enough to do glPushAttrib(GL_CURRENT_BIT | GL_POLYGON_BIT);

If that doesn't help with the color, you could also try
float fColor[4];
glGetFloatv(GL_CURRENT_COLOR, fColor);
and
glColor4fv(fColor);
outside the PushAttrib/PopAttrib part.

skynet
03-19-2009, 05:49 AM
I'd rather not push/pop any vertex attribute related data. Its better (and most probably cheaper) to just do an appopriate glColor() call right before you start drawing something. Relying on a certain color to be "default state" is for sure a bad practice.