glMatrixMode(GL_MODELVIEW)
command. Any matrix operations you perform from now on will be performed on the ModelView matrix. The most common operation to perform on the ModelView matrix is to simply use the gluLookAt() command. The form of this command is:
gluLookAt(eye_x, eye_y, eye_z, target_x, target_y, target_z, up_x, up_y, up_z)This will multiply the current matrix by the matrix necessary to be looking at target from eye with up vector up.
The following code fragment is a common use of the ModelView matrix:
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eye.x,eye.y,eye.z, target.x,target.y,target.z, 0,1,0);
OpenGL also has a projection matrix. This matrix is applied after the ModelView matrix and transforms coordinates from camera space to canonical projection space. Common use of this matrix is as follows:
glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40,1,.1,10);The gluPerspective(...) call forms the correct matrix to do a projection transformation with a Y field of view of 40 degrees, an X to Y aspect ratio of 1, a near clipping plane at .1, and a far clipping plane at 10.
If you desire a parallel projection instead of a perspective projection, you would use the glOrtho() call instead of gluPerspective(). See the manual for use of this call.