To main page | 3dengine.org

Projection Matrix


Projection matrix in OpenGL (GL_PROJECTION matrix) is one of three main OpenGL matrices, it defines the angle of view, aspect ratio, the near and far clipping ranges.

Basically it defines how big is the difference between the objects that are near and those that are far, or whether this is orthogonal mode; it determines the width to height ratio (aspect ratio) and how close or far the point should be from camera to be discarded.

Projection matrix is 4x4 matrix, stored in OpenGL in column major order, so it is stored like so (presented here in usual math notation):
[0  4  8   12]
[1  5  9   13]
[2  6  10  14]
[3  7  11  15]
Usually OpenGL calls return the array of 16 elements and this is how they are arranged to be used in real math.

See gluPerspective description for explanation of which element of matrix is which.

Get

C++
GLfloat buffer[16];
glGetFloatv( GL_PROJECTION_MATRIX, buffer);
PyOpenGL
buffer = glGetDouble( GL_PROJECTION_MATRIX)

OpenGL

The main calls that set projection matrix are gluPerspective, glFrustum and glDepthRange.

See also

OpenGL matrix abuse happens when projection matrix is used to store coordinates of camera looking at an object.