1SDL_SetPalette(3)              SDL API Reference             SDL_SetPalette(3)
2
3
4

NAME

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

SYNOPSIS

9       #include "SDL.h"
10
11       int  SDL_SetPalette(SDL_Surface *surface, int flags, SDL_Color *colors,
12       int firstcolor, int ncolors);
13

DESCRIPTION

15       Sets a portion of the palette for the given 8-bit surface.
16
17       Palettized (8-bit) screen surfaces with the SDL_HWPALETTE flag have two
18       palettes,  a logical palette that is used for mapping blits to/from the
19       surface and a physical palette (that determines how the  hardware  will
20       map the colors to the display). SDL_BlitSurface always uses the logical
21       palette when blitting surfaces (if it has to  convert  between  surface
22       pixel  formats). Because of this, it is often useful to modify only one
23       or the other palette to achieve various special  color  effects  (e.g.,
24       screen fading, color flashes, screen dimming).
25
26       This  function  can  modify  either  the logical or physical palette by
27       specifing SDL_LOGPAL or SDL_PHYSPALthe in the flags parameter.
28
29       When surface is the surface associated with the  current  display,  the
30       display  colormap  will  be  updated  with  the  requested  colors.  If
31       SDL_HWPALETTE was set in SDL_SetVideoMode  flags,  SDL_SetPalette  will
32       always  return  1,  and the palette is guaranteed to be set the way you
33       desire, even if the window colormap has to be warped or run under  emu‐
34       lation.
35
36       The  color components of a SDL_Color structure are 8-bits in size, giv‐
37       ing you a total of 256^3=16777216 colors.
38

RETURN VALUE

40       If surface is not a palettized surface,  this  function  does  nothing,
41       returning 0. If all of the colors were set as passed to SDL_SetPalette,
42       it will return 1. If not all the color  entries  were  set  exactly  as
43       given,  it will return 0, and you should look at the surface palette to
44       determine the actual color palette.
45

EXAMPLE

47               /* Create a display surface with a grayscale palette */
48               SDL_Surface *screen;
49               SDL_Color colors[256];
50               int i;
51               .
52               .
53               .
54               /* Fill colors with color information */
55               for(i=0;i<256;i++){
56                 colors[i].r=i;
57                 colors[i].g=i;
58                 colors[i].b=i;
59               }
60
61               /* Create display */
62               screen=SDL_SetVideoMode(640, 480, 8, SDL_HWPALETTE);
63               if(!screen){
64                 printf("Couldn't set video mode: %s
65       ", SDL_GetError());
66                 exit(-1);
67               }
68
69               /* Set palette */
70               SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256);
71               .
72               .
73               .
74               .
75

SEE ALSO

77       SDL_SetColors, SDL_SetVideoMode, SDL_Surface, SDL_Color
78
79
80
81SDL                         Tue 11 Sep 2001, 23:01           SDL_SetPalette(3)
Impressum