问题描述
我只是不明白OpenGL的glMatrixMode
是干什么的.
I just don't understand what OpenGL's glMatrixMode
is for.
据我所知,当glMatrixMode(GL_MODELVIEW)
被调用时,它后跟glVertex
,glTranslate
,glRotate
等,也就是说,OpenGL命令将某些对象放置空间.另一方面,如果glOrtho
或glFrustum
或gluProjection
被称为(即如何渲染放置的对象),它的调用先于glMatrixMode(GL_PROJECTION)
.
As far as I can see, when glMatrixMode(GL_MODELVIEW)
is called, it is followed by glVertex
, glTranslate
, glRotate
and the like,that is, OpenGL commands that place some objects somewhere inthe space. On the other hand, if glOrtho
or glFrustum
or gluProjection
is called (ie how the placed objects are rendered), it has a preceeding call of glMatrixMode(GL_PROJECTION)
.
我想到目前为止我写的是一个假设,有人会证明我错了,但不是完全使用不同的 Matrix模式的 point 因为有不同种类的gl功能:那些与放置对象以及具有如何渲染对象的对象?
I guess what I have written so far is an assumption on which someone will proveme wrong, but is not the point of using different Matrix Modes exactlybecause there are different kinds of gl-functions: those concerned withplacing objects and those with how the objects are rendered?
推荐答案
这很简单,可以很简单地回答:
This is simple and can be answered very briefly:
-
渲染顶点(如
glVertex
中所示)取决于称为模型-视图矩阵" 和"投影矩阵的矩阵的当前状态 ",
Rendering vertices (as in
glVertex
) depends on the current state of matrices called "model-view matrix" and "projection matrix",
命令glTranslatef
,glPushMatrix
,glLoadIdentity
,glLoadMatrix
,glOrtho
,gluPerspective
和整个族影响当前矩阵(可以是以上)
The commands glTranslatef
, glPushMatrix
, glLoadIdentity
, glLoadMatrix
, glOrtho
, gluPerspective
and the whole family affect the current matrix (which is either of the above),
命令glMatrixMode
选择受上述命令影响的矩阵(模型视图或投影).
The command glMatrixMode
selects the matrix (model-view or projection) which is affected by the forementioned commands.
(此外,还有用于纹理坐标的纹理矩阵,但很少使用.)
(Also, there's also the texture matrix used for texture coordinates, but it's seldomly used.)
所以常见的用例是:
- 大多数时候模型视图矩阵都处于活动状态,
- 每当您需要初始化投影矩阵时(通常是在开始时或调整窗口大小时),将活动对象切换为投影,设置透视图,然后返回到模型视图.
这篇关于为什么在OpenGL中有glMatrixMode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!