Simple info : CreateRGBSurface() convert an image with his palette
to a new image with a “universal palette” (All CreatedRGBSurface got
the same palette) or I’m wrong ?? (I’m never utilize it yet, but if it’s
that I’ll surely utilize it!)
Umm… I don’t think so. I’m not 100% sure, but I’m at least 90% sure that
CreateRGBSurface() doesn’t create a palette for you. (This is from running
v2.0 of sprite.c with an 8bpp video surface - I just got a black box)
In my quick testing, I’ve found that after calling SDL_CreateRGBSurface(),
you have to set the palette yourself before blitting to it if you want to
actually get an image onto it.
Strangely enough, using SDL_DisplayFormat() on a >8bit image to convert it
into an 8 bit image for display seems to work fine, even before I set the
video surface’s palette. How exactly does DisplayFormat() convert RGB
surfaces to palettized surfaces?
Oh I see now (don’t you love writing emails while playing around? :P) - the
video surface gets a default palette when it’s created. That explains
everything
So finally, I can actually answer this question! whew
No, SDL_CreateRGBSurface() does not automatically use a “global” palette; it
looks like it just gets filled in with zeroes, so unless you want to paint
in pure black, you’ll have to set it yourself.
If you want to use a global palette, you can do something like:
void set_palette (SDL_Surface *surface, SDL_Surface *screen)
{
if (screen == NULL)
screen = SDL_GetVideoSurface();
SDL_SetPalette (surface, SDL_LOGPAL | SDL_PHYSPAL,
screen->format->palette->colors,
0, screen->format->palette->ncolors);
} // end set_palette()
If you call that right after you create the surface (before attempting to
blit to/draw on it) then you will essentially have what you wanted. You’d
also better make sure you only call it if you really have a palettized
surface and display, otherwise it’ll probably crash (I think the palette is
NULL for RGB surfaces…?)
Hope this helps… :-)On Tue, 15 Jan 2002, Gerard wrote:
Mike.