glLoadIdentity和glPushMatrix/glPopMatrix,为什么不只使用前者呢?

qua*_*231 4 opengl graphics

将变换应用于对象时,我们使用glPushMatrix/glPopMatrix.但为什么我们不使用glLoadIdentity呢?

从而

    glPushMatrix()
    ..apply tranformations
    ...draw object
    glPopMatrix()
    glPushMatrix()
    ..apply tranformations
    ...draw object
    glPopMatrix()
Run Code Online (Sandbox Code Playgroud)

这应该是怎么做的吧?

可以变成

    glLoadIdentity()
    ..apply tranformations
    ...draw object
    glLoadIdentity()
    ..apply tranformations
    ...draw object
Run Code Online (Sandbox Code Playgroud)

Nic*_*las 8

因为你无法做到这一点:

glPushMatrix()
..apply tranformations
glPushMatrix()
..apply ADDITIONAL transformations
..draw object with combined transforms
glPopMatrix()
...draw object without the additional transforms.
glPopMatrix()
Run Code Online (Sandbox Code Playgroud)