GLPUSHMATRIX(3G)
β¨ NAME β¨
glPushMatrix, glPopMatrix β push and pop the current matrix stack π
okay so bestie, we're in the 3G manual page (that's the GL one, iykyk) and today's topic is the matrix stack. yes THE matrix stack. the one that runs your whole entire transform vibe. let's go π¦
π C SPECIFICATION
void glPushMatrix( void )
π C SPECIFICATION (yes again, it's two functions bestie)
void glPopMatrix( void )
π DESCRIPTION π
so. there is a stack of matrices for each of the matrix modes. Every mode gets its own lil stack, no sharing, no borrowing, periodt.
In GL_MODELVIEW mode, the stack depth is at least 32. In the other modes β GL_COLOR, const(PROJECTION), and GL_TEXTURE β the depth is at least 2. And the current matrix in any mode? That's just the matrix chillin' on the top of the stack for that mode. The main character of the stack, if you will. π
glPushMatrix pushes the current matrix stack down by one, duplicating the current matrix. Which means: after a glPushMatrix call, the matrix on top of the stack is identical to the one below it. It's giving twins. It's giving copy-paste but make it official. π«Ά
glPopMatrix pops the current matrix stack, replacing the current matrix with the one below it on the stack. Say bye to the top one, the runner-up is promoted. π
Initially, each of the stacks contains one matrix, an identity matrix. One (1) matrix. Alone. Iconic but lonely. πΈ
β οΈ okay so here's the serious part bestie, no cap: it is an error to push a full matrix stack, or to pop a matrix stack that contains only a single matrix. In either case, the error flag is set and no other change is made to GL state. So it fails cleanly β nothing else gets messed up β but the flag IS set. Respect the boundaries of the stack fr fr. π
π¨ ERRORS π¨
GL_STACK_OVERFLOWis generated ifglPushMatrixis called while the current matrix stack is full. Too much. Overflowing. The stack said "I cannot hold any more of your matrices, bestie." πGL_STACK_UNDERFLOWis generated ifglPopMatrixis called while the current matrix stack contains only a single matrix. You popped the last one. There's nothing left. Empty. Void. πGL_INVALID_OPERATIONis generated ifglPushMatrixorglPopMatrixis executed between the execution ofglBeginand the corresponding execution ofglEnd. Not insideglBegin/glEnd, we do NOT do that in this house. π
π ASSOCIATED GETS π
these are the glGet calls that let you peek at what's going on π:
glGetwith argumentGL_MATRIX_MODEglGetwith argumentGL_COLOR_MATRIXglGetwith argumentGL_MODELVIEW_MATRIXglGetwith argumentGL_PROJECTION_MATRIXglGetwith argumentGL_TEXTURE_MATRIXglGetwith argumentGL_COLOR_STACK_DEPTHglGetwith argumentGL_MODELVIEW_STACK_DEPTHglGetwith argumentGL_PROJECTION_STACK_DEPTHglGetwith argumentGL_TEXTURE_STACK_DEPTHglGetwith argumentGL_MAX_MODELVIEW_STACK_DEPTHglGetwith argumentGL_MAX_PROJECTION_STACK_DEPTHglGetwith argumentGL_MAX_TEXTURE_STACK_DEPTH
π¦ SEE ALSO π¦
go read these next, they're all part of the same friend group:
glFrustum(3G)glLoadIdentity(3G)glLoadMatrix(3G)glMatrixMode(3G)glMultMatrix(3G)glOrtho(3G)glRotate(3G)glScale(3G)glTranslate(3G)glViewport(3G)
and that's the whole page bestie!! π you now know literally everything about pushing and popping matrices. go forth and stack responsibly, and remember: full stack = GL_STACK_OVERFLOW, empty stack = GL_STACK_UNDERFLOW, and neither of them is the vibe. mwah π
this was the GLPUSHMATRIX(3G) page β 3G manual, GL section, same title top and bottom, cute lil footer and all. bye bestie, drink water, pop your matrices, slay π β¨
π¦ where this page comes from
- opensuse-leap 16.0: Mesa-libGL-devel 24.1.7-160000.3.1 Β· MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 Β· MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 Β· MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms