Game Development Reference
In-Depth Information
BYTE cStencilBits;
BYTE cAuxBuffers;
BYTE iLayerType;
BYTE bReserved;
DWORD dwLayerMask;
DWORD dwVisibleMask;
DWORD dwDamageMask;
} PIXELFORMATDESCRIPTOR;
We use a small fraction of the possible members in our example. First,
we set the size of the structure and the version number. In the example
we declare that our pixel format is suitable for OpenGL and that it is
double buffered using the bitwise Or-ed constants PFD_DRAW_TO_
WINDOW, PFD_SUPPORT_OPENGL and PFD_DOUBLEBUFFER.
Unfortunately, the use of double buffering means we cannot use any
GDI (Graphics Device Interface) methods to draw on this display in the
current Windows implementation of OpenGL. This means that we have
to use OpenGL to write text to the screen; the GDI function DrawText
will not work. You will see in a later chapter how the 'glu' functions can
be used to enable the use of multiple fonts in an OpenGL window. The
pixel format type is RGBA and the display window is 24 bit. The only
other member of the structure that we set is the depth buffer. For our
simple example we could actually get by without a depth buffer, since
just the use of backface culling ensures that the window paints
correctly. If you imagine a die, as you rotate it no more than three faces
are visible, all hidden faces are effectively back facing just using the
order of the points in the faces. See Chapter 1 for a more detailed
description of culling by the clockwise or counter-clockwise nature of
the vertices of a polygon.
Having set up the PIXELFORMATDESCRIPTOR structure, we then
choose this for our device context. The function 'ChoosePixelFormat'
tries to get the best match for the format you want on the device you
are using. Then you can set this pixel format for the device using
'SetPixelFormat'. If this fails then you cannot have an OpenGL window
on this device. If everything goes well then you can create a rendering
context using one of the 'wgl' functions, 'wglCreateContext'. Before you
can use this new rendering context for any drawing, you need to make
it the current rendering context using another 'wgl' function, 'wglMake-
Current'. Finally, we tell OpenGL to use a z -buffer by enabling the
depth test and that counter-clockwise-orientated polygons are the ones
that are front facing. The 'OnCreate' function is given in full below:
Search Nedrilad ::




Custom Search