how to undo glMaterial()?

Hi,

If some objects are rendered using material commands, glMaterial()'s, and then another set of objects need to be rendered using glColorMaterial(), what commands should I make between these two renderings so that the glMaterial()‘s won’t affect the 2nd set of objects’ rendering? Please help. Thanks.

Tony

You can push the GL_LIGHTING_BIT attribute group and pop it when done. Check out glPush/PopAttrib.

Hi,

I think glPushAttrib() and glPophAttrib() cannot solve my problem. The 1st set objects’ rendering affects the 2nd set objects’. The 1st set objects’ rendering is done by a 3rd party. I cannot place glPushAttrib() and glPophAttrib() there. And I cannot change the rendering sequence either. I really need to know how to disable their material setting. Please help. I will appreciate it very much.

Tony

So do it outside the third party stuff.

glPushAttrib(GL_LIGHTING_BIT);
//Call 3rd party stuff
glPopAttrib();
// Draw your own stuff

It’s either that or after you do the 3rd party stuff, you set the material back to the defaults (or whatever else you might want.) OpenGL is a state machine and the only way to “undo” a previously set state of something is with the push/pop stuff, or by setting the state back to the original value afterwards.

Hi,

Thanks for the replies. Could someone kindly tell me how to set the material back to the defaults? I cannot use attributes push/pop commands because my rendering is done in a function (subroutine) called by the 3rd party just before buffer swapping.

Tony

There does not exist a command like “glSetDefault” or anything related to default parameters.
At best, you could check the spec and get the initial state so that you can repeat it.

For instance, the initial emissive reflectance is black, so reseting emissive color to “default” is equivalent to calling this :
GLfloat black[4]={0,0,0,1};
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);

You have to call glMaterial for everything like GL_SPECULAR, GL_DIFFUSE, GL_AMBIENT, GL_SHININESS… each with its own “default” value read from the spec. You already have downloaded the spec, didn’t you ?

It appears they finally fixed the posting problem…

Anyway… as I tried to post yesterday:

MSDN lists the defaults as follows:
GL_AMBIENT = (0.2, 0.2, 0.2, 1.0)
GL_DIFFUSE = (0.8, 0.8, 0.8, 1.0)
GL_SPECULAR = (0.0, 0.0, 0.0, 1.0)
GL_EMISSION = (0.0, 0.0, 0.0, 1.0)
GL_SHININESS = 0

Also, you could STILL do the push/pop stuff, though it might not seem quite as nice.

void Display()
{
glPushAttrib(GL_LIGHTING_BIT);
Call3rdPartyStuff();
}

void CallbackForYourStuff()
{
glPopAttrib();
DrawYourStuff();
}

Hi,

Could someone tell me where to download the OpenGL spec mentioned in a previous post? Thanks so much.

Tony

check out www.opengl.org !