Next: 4.4.2 State Queries and Up: 4.4 Modal Previous: 4.4 Modal

4.4.1 The Matrix Stack

Three kinds of transformation matrices are used in OpenGL: the model-view matrix, which is applied to vertex coordinates; the texture matrix, which is applied to texture coordinates; and the projection matrix, which describes the viewing frustum and is applied to vertex coordinates after they are transformed by the model-view matrix. Each of these matrices is .

Any of one these matrices may be loaded with or multiplied by a general transformation; commands are provided to specify the special cases of rotation, translation and scaling (since these cases take only a few parameters to specify rather than the 16 required for a general transformation). A separate command controls a mode indicating which matrix is currently affected by any of these manipulations. In addition, each matrix type actually consists of a stack of matrices that can be pushed or popped. The matrix on the top of the stack is the one that is applied to coordinates and that is affected by matrix manipulation commands.

The retained state represented by these three matrix stacks simplifies specifying the transformations found in hierarchical graphical data structures. Other graphics APIs also employ matrix stacks, but often only as a part of more general attribute structures. But OpenGL is unique in providing three kinds of matrices which can be manipulated with the same commands. The texture matrix, for instance, can be used to effectively rotate or scale a texture image applied to primitive, and when combined with perspective viewing transformations, can even be used to obtain projective texturing effects such as spotlight simulation and shadow effects using shadow maps[14].


segal@asd.sgi.com
Fri Sep 23 17:28:42 PDT 1994