Platform SDK: DirectX

Step 2: Set the Palette

[Visual Basic]

The information in this section pertains only to applications written in C and C++. See DirectDraw Visual Basic Tutorials.

[C++]

After you create the palette, you pass the pointer to the DirectDrawPalette object (ddpal) to the primary surface by calling the IDirectDrawSurface7::SetPalette method, as shown in the following example.

ddrval = lpDDSPrimary->SetPalette(lpDDPal); 
 
if(ddrval != DD_OK) 
    // SetPalette failed. 
 

After you have called IDirectDrawSurface7::SetPalette, the DirectDrawPalette object is associated with the DirectDrawSurface object. Any time you need to change the palette, you simply create a new palette and set the palette again. (Although this tutorial uses these steps, there are other ways of changing the palette, as will be shown in later examples.)

Next: Step 3: Load a Bitmap on the Back Buffer