我对OpenGL push/pop矩阵的理解是错误的吗?

hou*_*oft 2 opengl drawing translation matrix

我偶然发现了一个我无法解释的OpenGL问题,除非我以某种方式误解了如何glPushMatrix()/ glPopMatrix()工作.

下面两段代码不应该具有完全相同的效果吗?

  glPushMatrix();
  glVertex3f(0,0,0);
  glTranslatef(c->e->coords[0], c->e->coords[1], c->e->coords[2]);
  glPopMatrix();
Run Code Online (Sandbox Code Playgroud)

VS

  glVertex3f(c->e->coords[0], c->e->coords[1], c->e->coords[2]);
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中,只有当我使用第二个时才会看到任何内容.我尝试在代码中完全相同的位置使用两段代码,不改变任何其他内容,而使用push/pop矩阵的代码不会在屏幕上绘制任何内容.

gen*_*ult 5

你不能glPushMatrix()/PopMatrix()在一个glBegin()/glEnd()街区内打电话.

glBegin():

在glBegin和glEnd之间只能使用GL命令的子集.命令是glVertex,glColor,glSecondaryColor,glIndex,glNormal,glFogCoord,glTexCoord,glMultiTexCoord,glVertexAttrib,glEvalCoord,glEvalPoint,glArrayElement,glMaterial和glEdgeFlag.此外,可以使用glCallList或glCallLists来执行仅包含前面命令的显示列表.如果在glBegin和glEnd之间执行任何其他GL命令,则设置错误标志并忽略该命令.

建议:使用顶点数组顶点缓冲区对象而不是经典的立即模式glBegin()/glEnd()块.