Game Development Reference
In-Depth Information
direct OpenGL to use a particular matrix by specifying which matrix mode
is being used with a call to 'glMatrixMode'. In the 'resize' function we use
the projection matrix. The first step in setting up a projection is to clear the
existing matrix, which we do by using the call to 'glLoadIdentity'. If you are
confident with matrices then you will realize this sets the leading diagonal
of the matrix to all ones, while all other entries are zero. The effect of
multiplying a matrix by an identity matrix is to leave the original matrix
unchanged. Mathematical identities always have this form. They leave the
original unchanged under some operation.
The most complicated call in the function is the use of 'gluPerspective'.
Since the function call begins with 'glu' this must come from the utility
library 'glu32.dll'. The declaration of this function is:
void
gluPerspective (GLdouble
fovy , GLdouble aspect , GLdouble
zNear , GLdouble zFar )
Here fovy specifies the field of view in degrees in the y direction. If this is
set to more than around 100°, then the display will have a highly distorted
'fish-eye' look. In order to make sure that squares remain looking square,
the renderer needs to know the aspect ratio of the current viewport.
Simply dividing the window width by the window height specifies this. Just
as the edge of the screen is determined by the size of the window,
OpenGL sets a near and far distance clip, so that things extremely close
to camera or distant disappear from view. For simple demos, setting this
to a large range suffices. However, in order to make the maximum use
from the z -buffer it is important to set realistic values for the near and far
clipping planes. If you always use some default value of, for example, 0.1
for near and 1 000 000 for far, yet all the geometry you draw is in the range
10-12, then the accuracy of the z -buffer will plummet. Setting the near
and far clipping planes to 5 and 20 will ensure that the z -buffer
calculations are considerably more accurate and if you use fog then it will
blend much more subtly if the range for the near and far clipping planes