SDL_SetPalette

Name

SDL_SetPalette -- Sets the colors in the palette of an 8-bit surface.

Synopsis

uses
SDL;

function SDL_SetPalette ( surface : PSDL_Surface; flags : Integer; colors : PSDL_Color; firstcolor : Integer; ncolors : Integer) : Integer;

Description

Sets a portion of the palette for the given 8-bit surface.

Palettized (8-bit) screen surfaces with the SDL_HWPALETTE flag have two palettes, a logical palette that is used for mapping blits to/from the surface and a physical palette (that determines how the hardware will map the colors to the display). SDL_BlitSurface always uses the logical palette when blitting surfaces (if it has to convert between surface pixel formats). Because of this, it is often useful to modify only one or the other palette to achieve various special color effects (e.g., screen fading, color flashes, screen dimming).

This function can modify either the logical or physical palette by specifing SDL_LOGPAL or SDL_PHYSPAL the 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 TSDL_Color structure are 8-bits in size, giving you a total of 2563=16777216 colors.

Return Value

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.

Example

        // Create a display surface with a grayscale palette
screen : PSDL_Surface;
colors : array[ 0..255 ] of TSDL_Color;
i : integer;
.
.
.
// Fill colors with color information
for i := 0 to 255 do
begin
colors[i].r := i;
colors[i].g := i;
colors[i].b := i;
end;

// Create display
screen := SDL_SetVideoMode( 640, 480, 8, SDL_HWPALETTE );
if ( screen = nil ) then
begin
MessageBox( 0, PChar( Format( 'Couldn''t set 640x480x8 video mode : %s', [SDL_GetError] ) ), 'Error', MB_OK or MB_ICONHAND );
halt( -1 );
end;

// Set palette
SDL_SetPalette( screen, SDL_LOGPAL or SDL_PHYSPAL, colors, 0, 256 );
.
.
.
.

See Also

SDL_SetColors, SDL_SetVideoMode, TSDL_Surface, TSDL_Color