Next: 2.5 Other Features Up: 2 OpenGL's Functionality Previous: 2.3.5 Stereo

2.4 Viewing

One of the most difficult initial hurdles in learning 3D graphics programming is how to properly set up a view. It is very easy to get a black screen because the viewing for the scene is not properly initialized.

3D computer graphics uses matrix transformations to properly orient, view, clip, and map the model to the screen. OpenGL's various stages in mapping vertices in object coordinates into pixels in window coordinates are pictured in Figure 4.

An OpenGL programmer is responsible for loading the modelview and projection matrices. The modelview matrix determines how the vertices of OpenGL primitives are transformed to eye coordinates. The projection matrix transforms vertices in eye coordinates to clip coordinates.

A number of OpenGL routines deal with manipulating these matrices. The glMatrixMode routine is called with an argument of GL_MODELVIEW or GL_PROJECTION to determine what is the current modifiable matrix. Then glLoadIdentity may be called to set the currently modifiable matrix to the identity matrix. Then routines such as glRotatef, glTranslatef, and glScalef may be called to manipulate the currently modifiable matrix. glLoadMatrixf loads a specific matrix and glMultMatrixf multiplies the current matrix by some specified matrix and store the result as the current matrix. Understanding exactly how these different commands should be properly used is beyond the scope of this article.

The final step in establishing a view of your model is the viewport transformation. It determines how the scene gets mapped onto the computer screen. The glViewport routine specifies the rectangle in the window of into which the final image is to be mapped. By default, the entire window is used. glViewport is commonly invoked when an OpenGL window is resized.


mjk@asd.sgi.com
Wed Oct 19 18:06:42 PDT 1994