#### Archived

This topic is now archived and is closed to further replies.

# Peter Palette Picked a Pickled problem !!

This topic is 6932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

lol, soz, thats first title came into my head, ok this is about DirectX palettes and the trouble I''m having, so if this aint your scene, better clear off before this gets hairy... OK, I can load in a pcx file, read it''s palette ok and store it, now what I cannot do, is read that palette into a DirectX IDirectDrawPalette *palette without the VERY LAST entry not being copied, why is this? I am posting up some source code for people to look at void CreatePalette(void **data) { struct pcx_file_data *filedata = (struct pcx_file_data *)*data; struct pcx_palette *new_palette = (struct pcx_palette *)malloc(256 * sizeof(struct pcx_palette)); memset(new_palette,0,256 * sizeof(struct pcx_palette)); unsigned char *pal_ptr = (unsigned char *)filedata->palette; for(int a=0;a<256;a++) { new_palettepalette); filedata->palette = (void *)new_palette; } The palette data is stored in a void pointer, just the way I thought it work best, got a better idea? let me know... This is how I am creating the DirectX Palette, this is weird, cause every other palette entry works ok, but the last one, nope, dont work void ApplyPalette(void **data, IDirectDraw4 *ddobject, IDirectDrawSurface4 *surface) { IDirectDrawPalette *lpddpal; struct pcx_file_data *filedata = (struct pcx_file_data *)*data; struct pcx_palette *srcpalette = (struct pcx_palette *)filedata->palette; PALETTEENTRY *destpalette = (PALETTEENTRY *)malloc(256 * sizeof(PALETTEENTRY)); // Fill palette memset(destpalette, 0, 256*sizeof(PALETTEENTRY)); for (int a=0;a<256;a++) { destpalette[a].peRed = srcpalette[a].red; destpalette[a].peGreen = srcpalette[a].green; destpalette[a].peBlue = srcpalette[a].blue; destpalette[a].peFlags = PC_NOCOLLAPSE; } // Create actual palette object if ((ddobject->CreatePalette( DDPCAPS_8BIT / DDPCAPS_ALLOW256 /DDPCAPS_INITIALIZE, destpalette,&lpddpal,NULL)) == DD_OK) { // Attach the palette (lpddpal) // to the primary surface (lpddsprimary) if ((surface->SetPalette(lpddpal)) == DD_OK) { // everything worked OutputDebugString("Palette Applied to the directX surface ok"); } } } Now, this works ok and the palette applies ok too, but the only problem is that the last colour, will not apply, dont know why, hope you can help, if you need to ask anything, go for it.... ok, I''ll leave it at that for now.... kosh '' Target=_Blank>Link

##### Share on other sites
why the fuck does this board mess up when you try and post source clippings !!!! shit fucking thing !!!

##### Share on other sites
yeah! i HATE that!

well first a question, are you running this in windowed mode? Windows reserves 20 colors by default, but you can get that down to 2 (the first and last). And I would assume that you, like most people, and like windows, have black as the first color. So you might not be noticing the fact that it is changing the first color as well.

Unfortunately, there is nothing you can do about this. If you are running Windows 2000, you can change the first and last colors too (after telling windows that you are going to but then your program wouldn''t be compatible with Win98 and before. If you aren''t even running in windowed mode, then this is all irrelevant and you''d have to show me the source!

Although I believe DirectX even reserves the first and last two by default, even in full-screen mode. This is easier to get around and involves just setting a flag.

This is the code I use to create a palette:
and I hope the board doesnt screw it up!
Note the DDPCAPS_ALLOW256 flag used with the DDPCAPS_8BIT flag. This allows all 256 colors to bet set.
Also not the PC_RESERVED that I use.

PALETTEENTRY pal[256];
int i;

ZeroMemory(pal,sizeof(PALETTEENTRY)*256);
for(i=0;i<256;i++) pal.peFlags = PC_RESERVED;
hRet = g_pDD->CreatePalette(DDPCAPS_8BIT / DDPCAPS_ALLOW256, pal, &g_pDDPal, NULL);

When you set the palette, set the peFlags to PC_RESERVED
this should fix your problem in fullscreen mode.

If you need to fix it in windowed mode, send me an email and I''ll describe how to fix it there (involves a bunch of API calls )

##### Share on other sites
AHHHHHHH stupid board!

for(i=0;i<256;i++) pal.peFlags = PC_RESERVED;
thta''s supposed to be

for(_i=0;_i<256;_i++) pal.peFlags[_i] = PC_RESERVED;

but without the _''s

and DDPCAPS_8BIT / DDPCAPS_ALLOW256 is supposed to have a pipe (bitwise OR) in the middle!

##### Share on other sites
you might not even need the PC_RESERVED in full-screen mode, but my programs are set to work in both windowed and full-screen, so i always use it

##### Share on other sites
If you want to post code like this:
while (1) {   yermomma;}

You need to do [ code ] and [ /code ] (without the spaces in the commands.

##### Share on other sites
thanks!

with all my complaining somebody finally spoke up

##### Share on other sites
Or you could use the opening and closing PRE html tag... does the same thing.

www.databyss.com
www.omlettesoft.com

"Don''t meddle in the affairs of wizards, for they are subtle and quick to anger."

• 15
• 13
• 35
• 39