NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
REL="HOME"
TITLE="SDL Library Documentation"
REL="UP"
TITLE="Video"
REL="PREVIOUS"
TITLE="SDL_SetColors"
HREF="sdlsetcolors.html"><
LINK
REL="NEXT"
TITLE="SDL_SetGamma"
HREF="sdlsetgamma.html"><
/HEAD
CLASS="REFENTRY"
BGCOLOR="#FFF8DC"
TEXT="#000000"
LINK="#0000ee"
VLINK="#551a8b"
ALINK="#ff0000"
CLASS="NAVHEADER"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
COLSPAN="3"
ALIGN="center"
>SDL Library Documentation<
/TH
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
HREF="sdlsetcolors.html"
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
HREF="sdlsetgamma.html"
ALIGN="LEFT"
NAME="SDLSETPALETTE"
CLASS="REFNAMEDIV"
NAME="AEN1102"
>SDL_SetPalette -- Sets the colors in the palette of an
8-bit surface.<
/DIV
CLASS="REFSYNOPSISDIV"
NAME="AEN1105"
CLASS="FUNCSYNOPSIS"
NAME="AEN1106"
CLASS="FUNCSYNOPSISINFO"
CLASS="FUNCDEF"
CLASS="FSFUNC"
>
(SDL_Surface *surface, int flags, SDL_Color *colors, int firstcolor, int ncolors
);<
/CODE
CLASS="REFSECT1"
NAME="AEN1112"
>Sets a portion of the palette
for the given
8-bit surface.<
/P
>Palettized (8-bit) screen surfaces with the
CLASS="LITERAL"
> 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
HREF="sdlblitsurface.html"
>
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
).<
/P
>This function can modify either the logical or physical palette by
CLASS="LITERAL"
> or
CLASS="LITERAL"
CLASS="PARAMETER"
>
CLASS="PARAMETER"
> is the surface associated with the current
display, the display colormap will be updated with the requested colors. If
CLASS="LITERAL"
HREF="sdlsetvideomode.html"
> flags,
CLASS="FUNCTION"
> will always return <
SPAN
CLASS="RETURNVALUE"
>,
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.<
/P
>The color components of a
HREF="sdlcolor.html"
CLASS="STRUCTNAME"
> structure
are 8-bits in size, giving you a total of
CLASS="REFSECT1"
NAME="AEN1132"
CLASS="PARAMETER"
> is not a palettized surface, this function
does nothing, returning <
SPAN
CLASS="RETURNVALUE"
>. If all of the colors were set
CLASS="FUNCTION"
>, it will return
CLASS="RETURNVALUE"
>. If not all the color entries were set exactly as
given, it will return <
SPAN
CLASS="RETURNVALUE"
>, and you should look at the
surface palette to determine the actual
color palette.<
/P
CLASS="REFSECT1"
NAME="AEN1140"
CLASS="PROGRAMLISTING"
> /* 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);
.
.
.
CLASS="REFSECT1"
NAME="AEN1143"
HREF="sdlsetcolors.html"
>,
HREF="sdlsetvideomode.html"
>,
HREF="sdlsurface.html"
>,
HREF="sdlcolor.html"
CLASS="NAVFOOTER"
ALIGN="LEFT"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
WIDTH="33%"
ALIGN="left"
VALIGN="top"
HREF="sdlsetcolors.html"
WIDTH="34%"
ALIGN="center"
VALIGN="top"
HREF="index.html"
WIDTH="33%"
ALIGN="right"
VALIGN="top"
HREF="sdlsetgamma.html"
WIDTH="33%"
ALIGN="left"
VALIGN="top"
WIDTH="34%"
ALIGN="center"
VALIGN="top"
HREF="video.html"
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>