Any information on making palette based graphics?

Hi.

I have been using SDL for RGB stuff for a while. Now I am trying to port
an old vga game that uses palette indexed graphics, and I am having lots
of trouble even creating a singe SDL_Surface from my palette and some
unsigned char’s. I believe I create the palette right, but so far all my
pictures come out black, when I try to do something like this:

void PutPix (int x, int y, int width, int height, const byte *sprt) {
//gl_putboxmask(x, y, width, height, sprt);
SDL_Rect dest;
printf(“PutPix\n”);
tmp = SDL_CreateRGBSurfaceFrom((void *) sprt, width, height, 8,
CurrentScreen->format->BitsPerPixel,
CurrentScreen->format->Rmask,
CurrentScreen->format->Gmask,
CurrentScreen->format->Bmask,
0);
SDL_SetPalette(tmp, SDL_LOGPAL, Colors, 0, 256);
SDL_SetPalette(tmp, SDL_PHYSPAL, Colors, 0, 256);

But, it does not work.

Is there some more info on working with palettes in SDL somewhere?

Mads–
Mads Bondo Dydensborg. @Mads_Bondo_Dydensbor
Each generation has the right to determine its own culture. Culture isn’t
just symphony orchestras, movies about dead British royalty and hard-bound
books. For some, culture is now also gaming, websites, chat and messaging
systems, TV shows, music and movies.
- Jon Katz, Slashdot, on youth culture.

is the surface pointed to by CurrentScreen also an 8bpp surface?

also, is the data pointed to by sprt being freed prior to the surface being
freed?

additionally, shouldn’t the 4th parameter also be equal to width?>From: Mads Bondo Dydensborg

Reply-To: sdl at libsdl.org
To: SDL at libsdl.org
Subject: [SDL] Any information on making palette based graphics?
Date: Thu, 13 Dec 2001 21:43:06 +0100 (CET)

Hi.

I have been using SDL for RGB stuff for a while. Now I am trying to port
an old vga game that uses palette indexed graphics, and I am having lots
of trouble even creating a singe SDL_Surface from my palette and some
unsigned char’s. I believe I create the palette right, but so far all my
pictures come out black, when I try to do something like this:

void PutPix (int x, int y, int width, int height, const byte *sprt) {
//gl_putboxmask(x, y, width, height, sprt);
SDL_Rect dest;
printf(“PutPix\n”);
tmp = SDL_CreateRGBSurfaceFrom((void *) sprt, width, height, 8,
CurrentScreen->format->BitsPerPixel,
CurrentScreen->format->Rmask,
CurrentScreen->format->Gmask,
CurrentScreen->format->Bmask,
0);
SDL_SetPalette(tmp, SDL_LOGPAL, Colors, 0, 256);
SDL_SetPalette(tmp, SDL_PHYSPAL, Colors, 0, 256);

But, it does not work.

Is there some more info on working with palettes in SDL somewhere?

Mads


Mads Bondo Dydensborg. madsdyd at challenge.dk
Each generation has the right to determine its own culture. Culture isn’t
just symphony orchestras, movies about dead British royalty and hard-bound
books. For some, culture is now also gaming, websites, chat and messaging
systems, TV shows, music and movies.
- Jon Katz, Slashdot, on youth culture.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Join the world?s largest e-mail service with MSN Hotmail.
http://www.hotmail.com

is the surface pointed to by CurrentScreen also an 8bpp surface?

Should be, yes, it is created like this:
SDL_SetVideoMode(320, 200, 8, SDL_HWPALETTE | SDL_DOUBLEBUF)

also, is the data pointed to by sprt being freed prior to the surface being
freed?

Nope, it is actually const. (This is a very old game, the graphics are
compiled into the executable).

additionally, shouldn’t the 4th parameter also be equal to width?

The one that is 8? I thought that was the depth?

void PutPix (int x, int y, int width, int height, const byte *sprt) {
//gl_putboxmask(x, y, width, height, sprt);
SDL_Rect dest;
printf(“PutPix\n”);
tmp = SDL_CreateRGBSurfaceFrom((void *) sprt, width, height, 8,
CurrentScreen->format->BitsPerPixel,
CurrentScreen->format->Rmask,
CurrentScreen->format->Gmask,
CurrentScreen->format->Bmask,
0);
SDL_SetPalette(tmp, SDL_LOGPAL, Colors, 0, 256);
SDL_SetPalette(tmp, SDL_PHYSPAL, Colors, 0, 256);

MadsOn Thu, 13 Dec 2001, Ernest Pazera wrote:


Mads Bondo Dydensborg. @Mads_Bondo_Dydensbor
Men of vast integrity are seldom popular. They are often crucified

                           - Dave Mallery

additionally, shouldn’t the 4th parameter also be equal to width?

The one that is 8? I thought that was the depth?

its pitch, not depth, i.e. the number of bytes that make up a scan line in
the image, which in an 8bpp surface would be the same as width, unless there
is some sort of padding for the scan lines(as is often found in bitmaps),
but i doubt that is the case._________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail.
http://www.hotmail.com