OpenGL matrix mode


There is a problem when switching matrix mode between GL_MODELVIEW and GL_PROJECTION. As an easy practice, we always glLoadIdentity() after glMatrixMode() to reset the matrix. Because of this, the object displayed in GL_MODELVIEW will be disappeared when we glLoadIdentity() in GL_PROJECTION. Actually, this is because after we glLoadIdentity(), the gluPerspective() (or whatever we have used in GL_PROJECTION) will be reset. That is why the object in GL_MODELVIEW will be disappeared. To make it appear, that means we need to set back the gluPerspective().

We can preserve the GL_PROJECTION without glLoadIdentity(). However, if we are using gluUnProject to get the coordinate, we need to use glLoadIdentity() to reset the GL_PROJECTION beforehand.

I spent 2 days to figure out this stupid problem… Orz

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s