My instructor says they can be used interchangeably to affect the projection matrix. He argues that gluLookAt()
is preferably used because of its 'relative simplicity due to its ability to define the viewing angle'. Is this true? I've seen code examples using both gluLookAt()
and glFrustum()
and I'm wondering why would the programmmer mix them.
Like in the cube.c example of the redbook appears:
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
**//why isn't this a call to glFrustum?**
glScalef(1.0, 2.0, 1.0);
glutWireCube(1.0);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
//why isn't this a call a call to gluLookAt()?
glMatrixMode(GL_MODELVIEW);
}
Both glFrustum
and gluLookAt
perform simple matrix multiplication. Check the man pages for equations for those matrices:
gluLookAt
glFrustum
Both of those can be replaced by a glMultMatrix*
call.
The most important difference is that glFrustum
is used most of the time to establish a perspective projection matrix (used internally by gluPerspective
), and gluLookAt
is a convenience method for specifying model-view matrices (usually: implementing a camera).
gluLookAt affects the ModelView matrix whereas, glFrustum/gluPerspective affect the Projection matrix. These are entirely two different matrices in the pipeline. gluLookAt is a utility method which is a combination of glRotate and glTranslate calls to move the "camera" to the appropriate point in space and point it to the desired location. Whereas, glFrustum/gluPerspective are methods which define a perspective viewing volume. Check out for more details in the OpenGL Red Book.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With