How to use glPushMatrix and glPopMatrix?

Simple question basically.
I seem to do it wrong for some reason since suddenly my scene partially stops “moving” relatively to the camera (object take a fixed position in the view, except the first drawn one).

When I want to keep my original centre of the world, do I have to puch my matrix after each time I pop it back?
IE:
push
draw thingy
pop
push
draw thingy
pop

Or should I do this differently?

Thank you!

is still waiting for his book to arive

Well it depends.Think of it this way.You have a current matrix slot and a matrix stack.Push pushes the matrix in the slot on the stack(but the matrix still stays in the slot!) and pop pops the top of the stack into the slot.So after the first pop you have the initial matrix say M in the slot.M isn’t on the stack though so if you want to get M after the second pop as well you’ll have to repush as you do.If you don’t you’ll get a stack underflow as you push one item and try to pop back two.I’d say yoyr problems lies somewhere else.

I think your on the right track.

// world view can be changed by the following
glTranslate
glRotate

or use

gluLookAt

// Object move/rotate
glPushMatrix() // Save current stack
glTranslate
glRotate
draw_object()
glPopMatrix() // Restore stack

What happens is the object inside the Push/pop is effected by the past translate/rotate, plus the translate/rotate inside the push/pop. But after the stack is pop’d only the translate/rotate before the push will effect other objects after.

Hope this helps

Thank you people,
I think I got the problem solved now… I THINK I forgot a pop at some point, thus causing a stack overflow after a number of frames.
I haven’t been able to locate the problem in the code. Perhaps I forgot to un-comment something at that point

Anyway, I still don’t know how to read out the error-values of an OpenGL application. I see in the references that push_matrix generates and GL_STACK_OVERFLOW error, but how can I show it on screen?

Thanks!