PDA

View Full Version : how to undo glMaterial()?



jyoung77
05-15-2003, 02:42 PM
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

Bob
05-15-2003, 03:58 PM
You can push the GL_LIGHTING_BIT attribute group and pop it when done. Check out glPush/PopAttrib.

jyoung77
05-16-2003, 08:50 AM
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

Deiussum
05-16-2003, 09:00 AM
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.

jyoung77
05-16-2003, 02:09 PM
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

vincoof
05-16-2003, 04:35 PM
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 ? http://www.opengl.org/discussion_boards/ubb/wink.gif

Deiussum
05-20-2003, 12:21 PM
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();
}

jyoung77
05-20-2003, 12:53 PM
Hi,

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

Tony

vincoof
05-21-2003, 03:49 AM
check out www.opengl.org (http://www.opengl.org/developers/documentation/index.html) ! http://192.48.159.181/discussion_boards/ubb/wink.gif