P
gluPerspective
Chapter 14
321
gluPerspective
gluPerspective: set up a perspective projection matrix.
C Specification
void gluPerspective(
GLdouble fovy,
GLdouble aspect,
GLdouble zNear,
GLdouble zFar)
Parameters
fovy Specifies the field of view angle, in degrees, in the Y direction.
aspect Specifies the aspect ratio that determines the field of view in the X
direction. The aspect ratio is the ratio of X (width) to Y (height).
zNear Specifies the distance from the viewer to the near clipping plane
(always positive).
zFar Specifies the distance from the viewer to the far clipping plane (always
positive).
Description
gluPerspective specifies a viewing frustum into the world coordinate system. In general,
the aspect ratio in gluPerspective should match the aspect ratio of the associated
viewport. For example, aspect = 2.0 means the viewer’s angle of view is twice as wide in
X as it is in Y. If the viewport is twice as wide as it is tall, it displays the image without
distortion.
The matrix generated by gluPerspective is multiplied by the current matrix, just as if
glMultMatrix were called with thegenerated matrix. To load theperspective matrix onto
the current matrix stack instead, precede the call to gluPerspective with a call to
glLoadIdentity.
Given f defined as cotangent(fovy / 2), the generated matrix is
A 000
0f 00
00B C
00-10
where:
A = f / aspect
B = (zFar + zNear) / (zNear - zFar)
C = (2 × zFar × zNear) / (zNear × zFar)