Sets the colors in the palette of an 8-bit surface.
If surface is not a palettized surface, this function does nothing, returning 0. If all of the colors were set as passed to SDL_SetPalette, it will return 1. If not all the color entries were set exactly as given, it will return 0, and you should look at the surface palette to determine the actual color palette.
This function can modify either the logical or physical palette by specifing SDL_LOGPAL or SDL_PHYSPALthe in the flags parameter.
When surface is the surface associated with the current display, the display colormap will be updated with the requested colors. If SDL_HWPALETTE was set in SDL_SetVideoMode flags, SDL_SetPalette will always return 1, and the palette is guaranteed to be set the way you desire, even if the window colormap has to be warped or run under emulation.
The color components of a SDL_Color structure are 8-bits in size, giving you a total of 2563=16777216 colors.
'flags' is one or both of: SDL_LOGPAL -- set logical palette, which controls how blits are mapped to/from the surface, SDL_PHYSPAL -- set physical palette, which controls how pixels look on the screen Only screens have physical palettes. Separate change of physical/logical palettes is only possible if the screen has SDL_HWPALETTE set.
SDL_SetColors() is equivalent to calling this function with flags = (SDL_LOGPAL|SDL_PHYSPAL).Binds to C-function call in SDL_video.h:
extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface *surface, int flags, SDL_Color *colors, int firstcolor, int ncolors)
/* Create a display surface with a grayscale palette */ SDL_Surface *screen; SDL_Color colors[256]; int i; . . . /* Fill colors with color information */ for(i=0;i<256;i++) { colors[i].r=i; colors[i].g=i; colors[i].b=i; } /* Create display */ screen=SDL_SetVideoMode(640, 480, 8, SDL_HWPALETTE); if(!screen) { printf("Couldn't set video mode: %s\n", SDL_GetError()); exit(-1); } /* Set palette */ SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); . . . .