Example of use of Pop/PushAttrib?

Who can give me an example about a “cool” use of PopAttrib and PushAttrib?

Push/PopAttrib is good when you are calling functions, and don’t know if a certain state is enabled/disabled, and you need to turn it on/off.

void foobar(void)
{
// hmm, wonder if depthdest is enabled or not?
// … and is fogging enabled or not?

glPushAttrib(GL_ENABLE_BIT);
glEnable(GL_DEPTH_TEST); // make sure depthtest is enabled
glDisable(GL_FOG); // make sure fogging is disabled

// draw objects here
.
.
.

// now we restore all flags to the state they had before we entered foobar()
glPopAttrib()

}

This is usefull if you want to keep fogging/depthtest in the same state after foobar() as you had before you entered foobar().

what’s up with the word foobar in the programming world? I see it all the time.

“Foobar” - I’m not sure.

But “Fubar” here in Manchester usually means “****ed Up Beyond All Recognition” maybe its the same with a different spelling?

Paul.

“Foo” is a generic word, and it means something like “anything”, or “any kind of object”, if I get it right. But where “bar” comes into the picture, I have no idea