How to clean up Matrix stacks

Back to basics again!

How to clean matrix stacks?
I mean glLoadMatrix, glLoadIdentity will just replace the current
Matrix - the matrix at the top of the stack. glPopMatrix() will
pop out just the matrix at the top - not the whole stack

Only way I can think of is calling glPopMatrix again and again
till one gets an error flag set. Is there ne simpler/cleaner way?

  • Chetan

Why do you need to “clean the matrix stack?”

You should always be making sure you have a glPop corresponding to ever glPush. Just like you should always have a delete/free for every new/malloc in C/C++.

Oh right!

  • Chetan