HJY bio photo

HJY

A Code Lover. Also good at cooking

Github
A tricky bug of my openGl project. Considering following code: [code lang="c"] glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fovy, aspect, near, far); glMatrixMode(GL_MODELVIEW) gluLookAt(posX, posY, posZ, lookAtX, lookAtY, lookAtZ, upX, upY, upZ); draw_object_a(); glPushMatrix(); glLoadIdentity(); draw_object_b(); glPopMatrix(); [/code]

Object A will render normal, while Object B will not, Why?

glutLookAt and glLoadIdentity both apply matrix transformation on the top matrix of modelView stack.After glLookAt called, the camera transformation is applied to matrix. But glLoadIdentity will simply replace it with a identity matrix.

So B will render without camera transformation, A will.

**Note B will still render with perspective transformation since projection matrix wasn't touched by glLoadIdentity