glPushAttrib() , glPopAttrib()

Hi all,

Does anyone know how to use this 2 lines and what they really mean?

I have tried looking at an old version of the “redbook” but I don’t really understand how it works.

I am looking in the direction of rendering a series of scenes but each scene must retain certain ‘parts’ of the previous scene.

I am using MFC with open GL and adopting the Doc/View architecture. This means that any data storage or processing is done in the Doc class.

For example, I have 5 cups on the screen. A change in a particular array variable in the Doc class should indicate whether each particular cup is filled with water or without. When variable 1 is changed, cup 1 is filled up and the scene should be rendered. When the next event to happen is variable 2 changing, cup 2 should fill up but cup 1 should retain its former look and the entire scene is rendered again.

Does this have anything to do with push and pop for the attribute bits? Or does anyone know the conventional and ‘correct’ method to do this? Pls help. Thanks.

I hope I have described the situation well enough for you to understand, if not, pls post a message to me for any clarification? Thanks alot!!

Nope, you can push an attribute of the OpenGL state.

if you for example want to use glDisable( GL_LIGHTING); and do not know the current state of this, then you can use glPushAttr… to save it’s current state, change it any way you want and then use glPopAttr… to restore it’s state when you are done.

Most people say that you should not use these functions because they can slow down OpenGL, instead you should keep track of the attributes state yourself.


Oh, that means I am looking in the wrong direction? Any advice as to the correct direction for me?

The push/pop is for use durring the rendering process to control how objects are rendered, has nothing to do with keeping or deleting objects.

Once the scene has been rendered to the screen all the data sent to the openGL is gone.
You must maintain the status of each object and redraw them anytime there is a change to the scene.

That means in your doc class when somedata has changed everthing must be redraw each time the screen is updated.