Game Development Reference
In-Depth Information
the display would simply show a flat coloured rectangle. If we carefully
choose the value for each pixel then we can display a photograph. If the
range of colours in the displayed bitmap is limited then we could choose
to store the bitmap as a combination of all the different colours used,
followed by a list of where to use these colours. This type of display is
called a palletized display and we are not supporting palletized displays in
this topic. Usually, palletized displays are limited to 256 colours. Creating
an optimized palette for each frame of animation is time consuming. The
alternative is to use a master palette, which has definite restrictions on the
way that the display can handle lighting. Imagine the simplest of scenes
with three bouncing balls all lit from above. Ball A is red, B is blue and C
is green. If the master palette has about 80 levels of red, green and blue,
then 240 slots in the palette have been used. Now in comes a purple,
yellow and orange cube. Somehow, this has to be displayed using the
remaining 16 colours; the results, while acceptable on desktop computer
platforms 10 years ago, simply do not cut it by today's standards.
Another type of display uses 16 bits for the colour value of each pixel.
This gives just 32 levels of red, 32 levels of green and 32 levels of blue.
This standard is often used in computer games, resulting in faster frame
rates with most hardware than 24-bit displays. A 32-bit display can use the
additional 8 bits for alpha or stencil use or it can be used by the display
driver to ensure all colour calculations use 32-bit integers. This results in
fewer instructions for the processor to handle and consequently faster
image transfers.
The code for the creation of the buffer is:
// Create a new empty Canvas with specified bitdepth
BOOL CCanvas::Create(int width, int height, int bitdepth)
// Delete any existing stuff.
if (m_bits)) delete m_bits;
// Allocate memory for the bits (DWORD aligned).
if (bitdepth==16) m_swidth =width*2;
if (bitdepth==24) m_swidth =width*3;
if (bitdepth==32) m_swidth =width*4;
m_swidth =( m_swidth + 3) & ~3;
m_size= m_swidth *height;
m_bits = new BYTE[m_size];
if (!m_bits) {
TRACE(”Out of memory for bits”);
return FALSE;
Search Nedrilad ::

Custom Search