Yes an encapsulating class already exists. But simply exchanging the pointer
to the palette does not work. SDL stores internally some sort of
colormapping, so the palette change has no effect. I believe it is stored in
the struct ‘map’ in the surface, which is inaccessible. With calling
SDL_SetColors for each surface, the animations work. But I have a large
amount of small tiles, so the way “copy palette from surface, change the
palette, copy it back to the surface via SDL_SetColors” has a noticeable
effect on the frame rate.
Anyone an idea how to solve this?
Yes, read what Pierre had to say!On Mon, Dec 15, 2008 at 3:10 PM, Christian Meyer wrote:
On Sat, Dec 13, 2008 at 11:02 AM, Pierre Phaneuf wrote:
If you change the physical palette (of which there’s just one), then
you’ll affect everything and you don’t need to redraw anything (if you
use a real paletted mode, it will just change colours, if not, SDL
will take care of emulating it for you).
What this means is: you need to make sure your display is actually in
8-bit palette mode, and then change the display palette, as opposed to
changing the palettes of the surfaces corresponding to your
images/animations. Individual surfaces can have palettes, as Pierre
pointed out, only to provide a means of blitting an 8-bit
palette-having surface to another surface, where the palette is used
to translate colors between the source and destination surface.
Here is what SDL_video.h has to say about the SDL_HWPALETTE flag which
you can pass to SDL_SetVideoMode()
- If SDL_HWPALETTE is set in ‘flags’, the SDL library will guarantee
- that the colors set by SDL_SetColors() will be the colors you get.
- Otherwise, in 8-bit mode, SDL_SetColors() may not be able to set all
- of the colors exactly the way they are requested, and you should look
- at the video surface structure to determine the actual palette.
- If SDL cannot guarantee that the colors you request can be set,
- i.e. if the colormap is shared, then the video surface may be created
- under emulation in system memory, overriding the SDL_HWSURFACE flag.
And here’s what it says about SDL_SetPalette()
/*
*/
extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface *surface, int flags,
SDL_Color *colors, int firstcolor,
int ncolors);
So to get the kind of highly efficiency palette-based animations that
you seek on the screen, you should probably add SDL_HWSURFACE |
SDL_FULLSCREEN | SDL_HWPALETTE to SDL_SetVideoMode(), and then use
SDL_SetPalette() with SDL_PHYSPAL in the flags argument.
Remember to share your work if you want!
–
http://codebad.com/