Search code examples
openglglulookat

Why before using gluLookAt I need to write glLoadIdentity


I found that if I don't use glLoadIdentity before gluLookAT, then I will see blank screen. I don't understand: why?


Solution

  • gluLookAt basically calculates a transformation matrix consiting of a translation (to the eye point you specified) and a rotation (to orient it). However, this transformation matrix is multiplied with the current matrix. So if the current matrix is not identiy, your camera will end up somewhere else, the rotation and translation operations will be additionally applied. Note that despite the name, gluLookAt can in princple be used to position and orient any object, not just the "camera".