Tricks of the Windows Game Programming Gurus:Advanced DirectDraw and Bitmapped Graphics

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

Here’s the code that creates a generic palette. You can change the code to use your own RGB value for the entries from 10 to 245, inclusive. This code simply makes them all gray:

    LPDIRECTDRAW4        lpdd;  // this is already setup

    PALETTEENTRY         palette[256]; // holds palette data

    LPDIRECTDRAWPALETTE  lpddpal = NULL; // palette interface

    // first set up the windows static entries

    // note it’s irrelevant what we make them

    for (int index = 0; index < 10 ; index++)

        {

        // the first 10 static entries

        palette[index].peFlags = PC_EXPLICIT;

        palette[index].peRed   = index;

        palette[index].peGreen = 0;

        palette[index].peBlue  = 0;

        // The last 10 static entries:

        palette[index+246].peFlags = PC_EXPLICIT;

        palette[index+246].peRed   = index+246;

        palette[index+246].peGreen = 0;

        palette[index+246].peBlue  = 0;

        }   // end for index

    // Now set up our entries. You would load these from

    // a file etc., but for now we’ll make them grey

    for (index = 10; index < 246; index ++)

        {

        palette[index].peFlags = PC_NOCOLLAPSE;

        palette[index].peRed   = 64;

        palette[index].peGreen = 64;

        palette[index].peBlue  = 64;

        }  // end for index

    // Create the palette.

    if (FAILED(lpdd->CreatePalette(DDPCAPS_8BIT, palette,

        &lpddpal,NULL)))

    {/* error */ }

    // attach the palette to the primary surface…

Notice the use of `PC_EXPLICIT` and `PC_NOCOLLAPSE`. `PC_EXPLICIT` means “these colors map to hardware,” and `PC_NOCOLLAPSE` means “don’t try to map these colors to other entries; leave them as they are.” If you wanted to animate some color registers, you would also logically `OR` the flag `PC_RESERVED`. This tells the palette manager not to map other Windows applications colors to the entry because it may change at any time.

### Summary

Without a doubt, this has been one of the longest chapters in the book. Hey, sue me! There was just a lot of material to cover. I could still keep going, but I want to leave some trees in the rain forest!

I’ve covered all kinds of stuff, including high-color modes, the blitter, clipping, color keys, sampling theory, windowed DirectDraw, GDI, and querying information from DirectDraw. Also, I’m done with the `T3DLIB1.CPP|H` library. You can check it out now if you want, or you can wait until the end of the next chapter when I go through each function.

In the next chapter, I’m going to take a break from DirectDraw for a bit (although it returns at the end of the chapter) and I’m going to cover some vector-based 2D geometry, transformations, and rasterization theory.

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.