|Mr. Palette||I'm trying to use an index palette to change the colors of the sprites in my game.
The DirectX7 SDK says to pass an array of bytes instead of an array of PALETTEENTRY types in the DirectDraw7.CreatePalette method, but I get type mismatch error.
An index palette is a palette that contains refrences to another palette's color table instead of a color table of its own.
|Eric Coleman||I don't know where you see that in the SDK, but my copy of the SDK says to pass an "array of 2, 4, 16, or 256 PALETTEENTRY types[...]."|
|Mr. Palette||Palette Types [Language: Visual Basic]
DirectDraw supports 1-bit (2 entry), 2-bit (4 entry), 4-bit (16 entry), and 8-bit (256 entry) palettes. A palette can only be attached to a surface that has a matching pixel format. For example, a 2-entry palette created with the DDPCAPS_1BIT flag can be attached only to a 1-bit surface created with the DDPF_PALETTEINDEXED1 flag.
Additionally, you can create palettes that don't contain a color table at all, known as index palettes. Instead of a color table, an index palette contains index values that represent locations in another palette's color table.
To create an indexed palette, specify the DDPCAPS_8BITENTRIES flag when calling the DirectDraw7.CreatePalette method. For example, to create a 4-bit indexed palette, specify both the DDPCAPS_4BIT and DDPCAPS_8BITENTRIES flags. When you create an indexed palette, you pass an array of bytes rather than an array of PALETTEENTRY types.
I copied that from the SDK. (DirectDraw\DirectDraw Essentials\Palettes\Palette Types)
I get a type mismatch error when I try to pass the array of bytes instead of PALETTEENTRY types.|
|Amrazek||What bit mode are you trying to use this in?|
|Eric Coleman||I see what you mean. Of course, this is not the only error in the SDK. Instead of using an indexed color palette, use a 256( or 254 ) color palette. If you want to change the colors of the sprites in your game, then use DirectDrawPalette.GetEntries and DirectDrawPalette.SetEntries to change the colors in the palette. This will change the colors in the game. Of course, you need to plan ahead to reserve entries in the palette for the sprites, or for color cycling.
Or if you still want to hack around with indexed color palletes, then you can create a 2-bit or 4-bit palette by packing the bytes into an array of PALETTEENTRY types. It would look something like this.
Dim PalBytes(0 To 0) As PALETTEENTRY
'a 2-bit array will hve 4 entries, or 4 bytes.
'Notice the order, which is important. The SDK
'lists the structure order just like below, which is the
'byte order is is in memory. Of course, you may want
'to use CopyMemory to test the byte order to make sure.
.blue = byte1
.flags = byte2
.green = byte3
.red = byte4
'Or if you want a 4-bit, that would be 16 bytes.
'so you should use the following for 16 bytes.
Dim PalBytes(0 To 3) As PALETTEENTRY
|Mr. Palette||What I'm trying to do with this is set the colors of the sprites in my game to a team (some little men have a red shirt and others have a blue shirt but still come from the same surface). An index palette would be perfect for this. All you need to do is set a few entries on the sprite before you blit it.
Is it even possible to use these index palettes in VB?????
Or is there another way to do this???|
|Eric Coleman||I have never used pallets in Direct Draw, but if you use the code I pasted above, you'll be able to use a PaletteEntry type as though it were an array of bytes. And thus create an indexed palette. That's all the help I can give you, I don't know of anyone that has used palettes (or even indexed palettes for that matter) in a Direct Draw program. This means that your only source of information will be the SDK, so you'll be doing something that no one else has done with VB. If you do get things working, you may want to consider writing a tutorial on it so other people can learn how to use indexed palettes.|