Contents / Previous / Next


General-Purpose Transformations

The commands glLoadMatrix*() and glMultMatrix*() allow to specify any transformation matrix directly and then to multiply the current matrix by that specified matrix.

You need to state whether you want to modify the modelview or projection matrix before supplying a transformation command. You do this with glMatrixMode():

void glMatrixMode(GLenum mode);

It specifies whether the modelview, projection, or texture matrix will be modified, using the argument GL_MODELVIEW, GL_PROJECTION, or GL_TEXTURE for mode. Subsequent transformation commands affect the specified matrix. Note that only one matrix can be modified at a time. By default, the modelview matrix is the one that is modifiable, and all three matrices contain the identity matrix.


You use the glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands.

     void glLoadIdentity(void);
Sets the currently modifiable matrix to the 4x4 identity matrix.

Typically, you always call this command before specifying projection or viewing transformations.


If you want to explicitly specify a particular matrix to be loaded as the current matrix, use glLoadMatrix*(). Similarly, use glMultMatrix*() to multiply the current matrix by the matrix passed in as an argument.

void glLoadMatrix{fd}(const TYPE *m);

void glMultMatrix{fd}(const TYPE *m);
The argument for both these commands is a vector of sixteen values (m1, m2, ... , m16) that specifies a matrix M.

If you are programming in C, and you declare a matrix as m[4][4], then the element m[i][j] is in the ith column and jth row of the OpenGL transformation matrix. This is the reverse of the standard C convention in which m[i][j] is in row i and column j. To avoid confusion, you should declare your matrices as m[16].