Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Index Palettes
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Mr. Palette
Neophyte

4 Posts

Posted - Mar 26 2003 :  2:07:49 PM  Show Profile  Reply with Quote
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
Gladiator

USA
811 Posts

Posted - Mar 26 2003 :  2:49:56 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
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[...]."

Go to Top of Page

Mr. Palette
Neophyte

4 Posts

Posted - Mar 26 2003 :  5:51:57 PM  Show Profile  Reply with Quote
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.

[Visual Basic]
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.
Go to Top of Page

Amrazek
Squire

40 Posts

Posted - Mar 26 2003 :  6:02:59 PM  Show Profile  Reply with Quote
What bit mode are you trying to use this in?
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Mar 26 2003 :  7:34:17 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
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.
With PalBytes(0)  
  .blue = byte1  
  .flags = byte2  
  .green = byte3  
  .red = byte4  
End With
  
'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  
  
Go to Top of Page

Mr. Palette
Neophyte

4 Posts

Posted - Mar 29 2003 :  1:43:58 PM  Show Profile  Reply with Quote
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???
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Mar 30 2003 :  10:45:32 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
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.

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.11 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.