Matrices in OpenGL

MatrixMode

OpenGL maintains a small number(4) of Matrices controlling various parts of the rendering pipeline. Only one of these matrices can be current for the purposes of manipulation. All matrix operations (e.g. transfomations) are applied to the 'current' Matrix, whatever the current matrix happens to be. Therefore is is important that the ModelView Matrix is selected as the current matrix before modeling or projection transformations begin. It is also a good idea to reset the matrix to the identity matrix before manipulation.

 

Selecting the current Matrix


Reseting or setting the current Matrix

Matrix Multiplication

All the following fuctions multiply the current matrix

Matrix Stack

The ModelView Matrix stack is used to save the current ModelView matrix. This is commonly used to 'undo' a sequence of transformations.

glPushMatrix() will copy the current ModelView matrix to the top of the stack ('saving' the sequence of trasformation so far).

glPopMatrix() removes the matrix off the top of the stack and and uses it to replace the current ModelView matrix. The effect is to restore the sate of the Modelview Matrix as it was at the last glPushMatrix().

The same effect can be accomlished by perfoming a sequence of transformations reversing the existing transformations, but this is slow and leads to rounding errors.