现在的位置: 首页 > 综合 > 正文

glPushMatrix 和glPopMatrix图解 —-求别笑

2014年08月29日 ⁄ 综合 ⁄ 共 884字 ⁄ 字号 评论关闭

猜想:

openGL在绘制场景时的一般用法是:

首先在函数的开始处用glLoadIdentity()设置当前的矩阵为单位矩阵。

然后在函数中用glPushMatrix()和glPopMatrix()函数进行操作:

 

根据实践判断:

即这两者是分开的,并不是当前矩阵就是栈中的最上端的矩阵。

当一开始进行glLoadIdentity时,在栈中并没有保存任何矩阵,只是将当前矩阵设置为单位矩阵;

当在程序中使用glPushMatrix 时,将当前的矩阵压入栈中

当在程序中使用glPopMatrix时,将栈中栈顶的矩阵取出放在当前矩阵中

 

以上猜想是错误的。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

教训:没有直接看人家给的API说明文档。。。。

 

实际是这样的:

There is a stack of matrices for each ofthe matrix modes. In GL_MODELVIEW mode, the stack depth is at least 32.In the other two modes,GL_PROJECTION and
GL_TEXTURE, the depthis at least 2.The currentmatrix in any mode is the matrix on the top of the stack for that mode.

glPushMatrix pushes the current matrix stack down by one, duplicatingthe current matrix. That is, after aglPushMatrix call, the matrix onthe top of the stack is identical to the one below it.

glPopMatrix pops thecurrent matrix stack, replacing the current matrix with the one below it on thestack.

Initially, each of the stacks contains one matrix, anidentity matrix.

红色标注的是current matrix

抱歉!评论已关闭.