Beginner's Guide to Modern PC Demo Coding

Volume 1, Chapter 2: Setting up the Palette


Right, at the moment we have set the display mode. Before we start plotting pixels, we need to be in control of what colour we are going to be plotting! That's why we are going to start to look at the palette.

As I said in the first tutorial, we are going to start looking at 256 colour palettes, which should be more than enough unless you are some amazing artist! When we start looking at certain effects which demand more colour we shall look at High and True colour.

To create a palette in Direct X, you simply create an 256 elemant array of a palette data structure supplied by Microsoft:

PALETTEENTRY palette[256];

PALETTEENTRY is made up of 4 byte-sized elements:

typedef struct tagPALETTEENTRY
 BYTE peRed;
 BYTE peGreen;
 BYTE peBlude;
 BYTE peFlags;

Filling up the Red, Green and Blue elements (with values 0-255) results in a colour. Just set peFlags to PC_NOCALLAPSE for now.

Next, we need to create the palette interface for use with DirectDraw and attach it to the DirectDraw interface:

 // produce error

The DDPCAPS control flags mean this:

DDCAPS_8BIT = Set 8 bit colour
DDCAPS_ALLOW256 = Allows you to set colour elements 0 and 256 usually reserved for black and white.
DDCAPS_INITIALIZE = Enables the palette data sent to be downloaded into the hardware palette.

Thare are others you can use but these are all you need for 8 bit colour.

This is a bit of a nightmare place to end a tutorial but the next part is a topic I would like to dedicate the whole tutorial too.

Coming up in part 3:

Video surfaces, page flipping and finally plotting that first pixel!