glPopMatrix

glPushMatrix、glPopMatrix操作其實就相當於棧里的入棧和出棧。許多人不明白的可能是入的是什麼,出的又是什麼。你當前的坐標系原點在你電腦螢幕的左上方。現在你調用glPushMatrix,然後再調用一堆平移、旋轉代碼等等,然後再畫圖。那些平移和旋轉都是基於坐上角為原點進行變化的。而且都會改變坐標的位置,經過了這些變化後,你的坐標肯定不再左上角了。那如果想恢復怎么辦呢?這時就調用glPopMatrix從棧里取出一個“狀態”了,這個狀態就是你調用glPushMatrix之前的那個狀態。就如很多opengl的書上所講:調用glPushMatrix其實就是把當前狀態做一個副本放入堆疊之中。

glPopMatrix
NAME
glPushMatrix, glPopMatrix -- push and pop the current matrix stack
C SPECIFICATION
void glPushMatrix(void void)
C SPECIFICATION
void glPopMatrix(void void)
DESCRIPTION
There is a stack of matrices for each of the matrix modes. In GL_MODELVIEW mode, the stack depth is at least 32. In the other two modes, GL_PROJECTION and GL_TEXTURE, the depth is at least 2. The current matrix in any mode is the matrix on the top of the stack for that mode.
glPushMatrix pushes the current matrix stack down by one, duplicating the current matrix. That is, after a glPushMatrix call, the matrix on the top of the stack is identical to the one below it.
glPopMatrix pops the current matrix stack, replacing the current matrix with the one below it on the stack.
Initially, each of the stacks contains one matrix, an identity matrix.
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. 彈出棧頂的矩陣,並將其刪除。這樣,原來從棧頂數位於第二位的矩陣將成為棧頂矩陣。當前堆疊由函式glMatrixMode()指定。如果矩陣堆疊中只有一個矩陣,調用函式將導致錯誤。
ERRORS
GL_STACK_OVERFLOW is generated if glPushMatrix is called while the current matrix stack is full.
GL_STACK_UNDERFLOW is generated if glPopAttrib is called while the current matrix stack contains only a single matrix.
GL_INVALID_OPERATION is generated if glPushMatrix is called between a call to glBegin and the corresponding call to glEnd.

相關詞條

相關搜尋

熱門詞條

聯絡我們