glFrustum
The glFrustum function multiplies the current matrix by a perspective matrix.
void glFrustum(
GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar);
Parameters
- left, right
The coordinates for the left- and right-vertical clipping planes. - bottom, top
The coordinates for the bottom- and top-horizontal clipping planes. - znear, zfar
The distances to the near- and far-depth clipping planes. Both distances must be positive.
Remarks
The glFrustum function describes a perspective matrix that produces a perspective projection. The (left, bottom, znear) and (right, top, znear) parameters specify the points on the near clipping plane that are mapped to the lower-left and upper-right corners of the window, respectively, assuming that the eye is located at (0, 0, 0). The zfar parameter specifies the location of the far clipping plane. Both znear and zfar must be positive. The corresponding matrix is:
The glFrustum function multiplies the current matrix by this matrix, with the result replacing the current matrix. That is, if M is the current matrix and F is the frustum perspective matrix, then glFrustum replaces M with M • F.
Use glPushMatrix and glPopMatrix to save and restore the current matrix stack.
Depth-buffer precision is affected by the values specified for znear and zfar. The greater the ratio of zfar to znear is, the less effective the depth buffer will be at distinguishing between surfaces that are near each other. If
roughly log (2) r bits of depth buffer precision are lost. Because r approaches infinity as znear approaches zero, you should never set znear to zero.
The following functions retrieve information about glFrustum:
glGet with argument GL_MATRIX_MODE
glGet with argument GL_MODELVIEW_MATRIX
glGet with argument GL_PROJECTION_MATRIX
glGet with argument GL_TEXTURE_MATRIX
Error Codes
The following are the error codes generated and their conditions.
Error code | Condition |
---|---|
GL_INVALID_VALUE | znear or zfar was not positive. |
GL_INVALID_OPERATION | glFrustum was called between a call to glBegin and the corresponding call to glEnd. |
Requirements
** Windows NT/2000:** Requires Windows NT 3.5 or later.
** Windows 95/98:** Requires Windows 95 or later. Available as a redistributable for Windows 95.
** Header:** Declared in Gl.h.
** Library:** Use Opengl32.lib.
See Also
glBegin, glEnd, glGet, glMatrixMode, glMultMatrix, glOrtho, glPopMatrix, glPushMatrix, glViewport