Game Development Reference
2 Drawing points and
polygons the hard way
Some people like to climb mountains, others prefer to fly over them
sipping a chilled wine. If you are a climber then this chapter is for you.
Most of this topic uses the OpenGL library, which originated on the SGI
platform and is now available for Windows, Mac and Unix boxes. The
advantage of using such a library is that it shields much of the complexity
of displaying the 3D characters we create. Another very definite benefit is
that the library takes advantage of any hardware the user may have
installed. The disadvantage to the climbers is that we have no
understanding of how the display is actually generated at the individual
pixel level. This chapter takes you through this process; if you are a
climber then read on, if you are a flyer then feel free to skip this chapter,
no one will ever know!
Creating memory for a background display
In this chapter we are trying to avoid using Windows-specific code
wherever possible. For this reason we use a class library that deals with
a memory-based bitmap . This class library, which is supplied as part of
the sample code for this chapter on the CD, is called CCanvas. CCanvas
has a constructor that can be supplied with a width and a height in pixels,
together with the bit depth.
A colour can be specified in many ways. Generally you will need a red
value, a green value and a blue value. Many applications allow for 256
levels of red, 256 levels of green and 256 levels of blue. Zero to 255 is the
range of values available in 1 byte. One byte contains 8 bits of
information. Hence with 8 bits for red, 8 bits for green and 8 bits for blue,
we have a 24-bit colour value, 8 + 8 + 8.
When colour is specified using 3 bytes in this topic, it is called an RGB
value. If we define the colour value for an array of pixels then we can
display this as a bitmap. If the value for each pixel were the same, then