Why is there a glMatrixMode in OpenGL?

后端 未结 4 539
攒了一身酷
攒了一身酷 2021-02-05 13:10

I just don\'t understand what OpenGL\'s glMatrixMode is for.

As far as I can see, when glMatrixMode(GL_MODELVIEW) is called, it is followed by

4条回答
  •  面向向阳花
    2021-02-05 13:23

    This is simple and can be answered very briefly:

    • Rendering vertices (as in glVertex ) depends on the current state of matrices called "model-view matrix" and "projection matrix",

    • The commands glTranslatef, glPushMatrix, glLoadIdentity, glLoadMatrix, glOrtho, gluPerspective and the whole family affect the current matrix (which is either of the above),

    • 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.)

    So the common use case is:

    • have the model-view matrix active most of the time,
    • whenever you have to initialize the projection matrix (usually at the beginning or when the window is resized, perhaps), switch the active to projection, set up a perspective, and revert back to model-view.

提交回复
热议问题