PDA

View Full Version : Turning off glMaterial ??



11-18-2002, 10:05 PM
Once you've made a call to glMaterialfv(...) is there a way to return to the state before this call was made?
I've written a program for exploring what an object (a sphere) will look like as I change the RGBA reflection coeffecients. Code in question looks something like this:

if (mat_amb_cb == 1) glMaterialfv(GL_FRONT, GL_AMBIENT, matAmb);
if (mat_dif_cb == 1) glMaterialfv(GL_FRONT, GL_DIFFUSE, matDif);
...
drawSphere();
...

The if statments are not excuted till I check the appropriate check box. Once they are unchecked, and those lines are not longer executed in the rendering routine the sphere will still retain those material properties.
Why???

Bob
11-18-2002, 11:50 PM
glPush/PopAttrib will save and restore states. However, I have a feeling you can't use it in this case, so I suppose you have to save the material before changing it. Either keep it yourself in a variable or get it from OpenGL with glGetMaterial.

11-19-2002, 09:14 AM
Bob,

Using glPushAttrib(GL_LIGHTING) & glPopAttrib() does exactly what I asked for, thanks.