1<HTML 2><HEAD 3><TITLE 4>SDL_SetPalette</TITLE 5><META 6NAME="GENERATOR" 7CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+ 8"><LINK 9REL="HOME" 10TITLE="SDL Library Documentation" 11HREF="index.html"><LINK 12REL="UP" 13TITLE="Video" 14HREF="video.html"><LINK 15REL="PREVIOUS" 16TITLE="SDL_SetColors" 17HREF="sdlsetcolors.html"><LINK 18REL="NEXT" 19TITLE="SDL_SetGamma" 20HREF="sdlsetgamma.html"></HEAD 21><BODY 22CLASS="REFENTRY" 23BGCOLOR="#FFF8DC" 24TEXT="#000000" 25LINK="#0000ee" 26VLINK="#551a8b" 27ALINK="#ff0000" 28><DIV 29CLASS="NAVHEADER" 30><TABLE 31SUMMARY="Header navigation table" 32WIDTH="100%" 33BORDER="0" 34CELLPADDING="0" 35CELLSPACING="0" 36><TR 37><TH 38COLSPAN="3" 39ALIGN="center" 40>SDL Library Documentation</TH 41></TR 42><TR 43><TD 44WIDTH="10%" 45ALIGN="left" 46VALIGN="bottom" 47><A 48HREF="sdlsetcolors.html" 49ACCESSKEY="P" 50>Prev</A 51></TD 52><TD 53WIDTH="80%" 54ALIGN="center" 55VALIGN="bottom" 56></TD 57><TD 58WIDTH="10%" 59ALIGN="right" 60VALIGN="bottom" 61><A 62HREF="sdlsetgamma.html" 63ACCESSKEY="N" 64>Next</A 65></TD 66></TR 67></TABLE 68><HR 69ALIGN="LEFT" 70WIDTH="100%"></DIV 71><H1 72><A 73NAME="SDLSETPALETTE" 74></A 75>SDL_SetPalette</H1 76><DIV 77CLASS="REFNAMEDIV" 78><A 79NAME="AEN1517" 80></A 81><H2 82>Name</H2 83>SDL_SetPalette -- Sets the colors in the palette of an 8-bit surface.</DIV 84><DIV 85CLASS="REFSYNOPSISDIV" 86><A 87NAME="AEN1520" 88></A 89><H2 90>Synopsis</H2 91><DIV 92CLASS="FUNCSYNOPSIS" 93><A 94NAME="AEN1521" 95></A 96><P 97></P 98><PRE 99CLASS="FUNCSYNOPSISINFO" 100>#include "SDL.h"</PRE 101><P 102><CODE 103><CODE 104CLASS="FUNCDEF" 105>int <B 106CLASS="FSFUNC" 107>SDL_SetPalette</B 108></CODE 109>(SDL_Surface *surface, int flags, SDL_Color *colors, int firstcolor, int ncolors);</CODE 110></P 111><P 112></P 113></DIV 114></DIV 115><DIV 116CLASS="REFSECT1" 117><A 118NAME="AEN1527" 119></A 120><H2 121>Description</H2 122><P 123>Sets a portion of the palette for the given 8-bit surface.</P 124><P 125>Palettized (8-bit) screen surfaces with the 126<TT 127CLASS="LITERAL" 128>SDL_HWPALETTE</TT 129> flag have two palettes, a logical 130palette that is used for mapping blits to/from the surface and a 131physical palette (that determines how the hardware will map the colors 132to the display). <A 133HREF="sdlblitsurface.html" 134>SDL_BlitSurface</A 135> 136always uses the logical palette when blitting surfaces (if it has to 137convert between surface pixel formats). Because of this, it is often 138useful to modify only one or the other palette to achieve various 139special color effects (e.g., screen fading, color flashes, screen dimming).</P 140><P 141>This function can modify either the logical or physical palette by 142specifing <TT 143CLASS="LITERAL" 144>SDL_LOGPAL</TT 145> or 146<TT 147CLASS="LITERAL" 148>SDL_PHYSPAL</TT 149>the in the <TT 150CLASS="PARAMETER" 151><I 152>flags</I 153></TT 154> 155parameter.</P 156><P 157>When <TT 158CLASS="PARAMETER" 159><I 160>surface</I 161></TT 162> is the surface associated with the current 163display, the display colormap will be updated with the requested colors. If 164<TT 165CLASS="LITERAL" 166>SDL_HWPALETTE</TT 167> was set in <A 168HREF="sdlsetvideomode.html" 169>SDL_SetVideoMode</A 170> flags, 171<TT 172CLASS="FUNCTION" 173>SDL_SetPalette</TT 174> will always return <SPAN 175CLASS="RETURNVALUE" 176>1</SPAN 177>, 178and the palette is guaranteed to be set the way you desire, even if the window 179colormap has to be warped or run under emulation.</P 180><P 181>The color components of a 182<A 183HREF="sdlcolor.html" 184><SPAN 185CLASS="STRUCTNAME" 186>SDL_Color</SPAN 187></A 188> structure 189are 8-bits in size, giving you a total of 190256<SUP 191>3</SUP 192>=16777216 colors.</P 193></DIV 194><DIV 195CLASS="REFSECT1" 196><A 197NAME="AEN1547" 198></A 199><H2 200>Return Value</H2 201><P 202>If <TT 203CLASS="PARAMETER" 204><I 205>surface</I 206></TT 207> is not a palettized surface, this function 208does nothing, returning <SPAN 209CLASS="RETURNVALUE" 210>0</SPAN 211>. If all of the colors were set 212as passed to <TT 213CLASS="FUNCTION" 214>SDL_SetPalette</TT 215>, it will return 216<SPAN 217CLASS="RETURNVALUE" 218>1</SPAN 219>. If not all the color entries were set exactly as 220given, it will return <SPAN 221CLASS="RETURNVALUE" 222>0</SPAN 223>, and you should look at the 224surface palette to determine the actual color palette.</P 225></DIV 226><DIV 227CLASS="REFSECT1" 228><A 229NAME="AEN1555" 230></A 231><H2 232>Example</H2 233><PRE 234CLASS="PROGRAMLISTING" 235> /* Create a display surface with a grayscale palette */ 236 SDL_Surface *screen; 237 SDL_Color colors[256]; 238 int i; 239 . 240 . 241 . 242 /* Fill colors with color information */ 243 for(i=0;i<256;i++){ 244 colors[i].r=i; 245 colors[i].g=i; 246 colors[i].b=i; 247 } 248 249 /* Create display */ 250 screen=SDL_SetVideoMode(640, 480, 8, SDL_HWPALETTE); 251 if(!screen){ 252 printf("Couldn't set video mode: %s\n", SDL_GetError()); 253 exit(-1); 254 } 255 256 /* Set palette */ 257 SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); 258 . 259 . 260 . 261 .</PRE 262></DIV 263><DIV 264CLASS="REFSECT1" 265><A 266NAME="AEN1558" 267></A 268><H2 269>See Also</H2 270><P 271><A 272HREF="sdlsetcolors.html" 273>SDL_SetColors</A 274>, 275<A 276HREF="sdlsetvideomode.html" 277>SDL_SetVideoMode</A 278>, 279<A 280HREF="sdlsurface.html" 281>SDL_Surface</A 282>, 283<A 284HREF="sdlcolor.html" 285>SDL_Color</A 286></P 287></DIV 288><DIV 289CLASS="NAVFOOTER" 290><HR 291ALIGN="LEFT" 292WIDTH="100%"><TABLE 293SUMMARY="Footer navigation table" 294WIDTH="100%" 295BORDER="0" 296CELLPADDING="0" 297CELLSPACING="0" 298><TR 299><TD 300WIDTH="33%" 301ALIGN="left" 302VALIGN="top" 303><A 304HREF="sdlsetcolors.html" 305ACCESSKEY="P" 306>Prev</A 307></TD 308><TD 309WIDTH="34%" 310ALIGN="center" 311VALIGN="top" 312><A 313HREF="index.html" 314ACCESSKEY="H" 315>Home</A 316></TD 317><TD 318WIDTH="33%" 319ALIGN="right" 320VALIGN="top" 321><A 322HREF="sdlsetgamma.html" 323ACCESSKEY="N" 324>Next</A 325></TD 326></TR 327><TR 328><TD 329WIDTH="33%" 330ALIGN="left" 331VALIGN="top" 332>SDL_SetColors</TD 333><TD 334WIDTH="34%" 335ALIGN="center" 336VALIGN="top" 337><A 338HREF="video.html" 339ACCESSKEY="U" 340>Up</A 341></TD 342><TD 343WIDTH="33%" 344ALIGN="right" 345VALIGN="top" 346>SDL_SetGamma</TD 347></TR 348></TABLE 349></DIV 350></BODY 351></HTML 352>