If you don’t understand what I’m asking, I mean –
glPushMatrix();
glPushMatrix();
glPushMatrix();
glPushMatrix(); // push matrix 4 times
glTranslatef(...);
//do stuff
glPopMatrix(); // pull it up 1, so we can do more stuff
glTranslatef(...);
// do stuff
glPopMatrix(); // and again, and again, etc
glTranslatef(...);
// do stuff
glPopMatrix();
glTranslatef(...);
// do stuff
glPopMatrix();
Would everything still work out?
Yes,
glPushMatrixpushes the current matrix of the current matrixmode (GL_PROJECTION,GL_MODELVIEW, etc.) to a matrix stack,glPopMatrixpops the first one back. There are separate stacks for each matrixmode.It doesn’t look there’s an old enough official OpenGL man page to have the documentation on this method, but this site came up as one of the first results and contains the same text: http://www.manpagez.com/man/3/glPushMatrix/
According to that page, it looks like
GL_MODELVIEWstack is guaranteed to be at least 32 matrices deep, and all the other ones at least 2 deep. On modern cards they’re probably much higher. You can poll the exact number by callingglGetwith the proper parameter for stack depth, i.e.GL_MODELVIEW_STACK_DEPTHorGL_PROJECTION_STACK_DEPTH, etc.Also, the matrix stack was deprecated a long time ago in favor of user-managed matrices. If you’re writing a small program or just learning, it’s totally fine to use deprecated OpenGL. Just felt like I should mention it for the sake of completeness regarding OpenGL matrices.