Turning off glMaterial ??

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);


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.

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.


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