docs/man3/SDL_SetColors.3
author Sam Lantinga <slouken@libsdl.org>
Wed, 08 Mar 2006 18:30:12 +0000
changeset 1486 9d77fc9d0ace
parent 181 e5bc29de3f0a
child 2283 546f7c1eb755
permissions -rw-r--r--
Re-added C runtime support for Visual C++ 5,6
slouken@181
     1
.TH "SDL_SetColors" "3" "Tue 11 Sep 2001, 23:01" "SDL" "SDL API Reference" 
slouken@0
     2
.SH "NAME"
slouken@0
     3
SDL_SetColors\- Sets a portion of the colormap for the given 8-bit surface\&.
slouken@0
     4
.SH "SYNOPSIS"
slouken@0
     5
.PP
slouken@0
     6
\fB#include "SDL\&.h"
slouken@0
     7
.sp
slouken@0
     8
\fBint \fBSDL_SetColors\fP\fR(\fBSDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors\fR);
slouken@0
     9
.SH "DESCRIPTION"
slouken@0
    10
.PP
slouken@0
    11
Sets a portion of the colormap for the given 8-bit surface\&.
slouken@0
    12
.PP
slouken@0
    13
When \fBsurface\fR is the surface associated with the current display, the display colormap will be updated with the requested colors\&. If \fBSDL_HWPALETTE\fP was set in \fISDL_SetVideoMode\fR flags, \fBSDL_SetColors\fP will always return \fB1\fR, 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\&.
slouken@0
    14
.PP
slouken@0
    15
The color components of a \fI\fBSDL_Color\fR\fR structure are 8-bits in size, giving you a total of 256^3 =16777216 colors\&.
slouken@0
    16
.PP
slouken@0
    17
Palettized (8-bit) screen surfaces with the \fBSDL_HWPALETTE\fP 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)\&. \fBSDL_SetColors\fP modifies both palettes (if present), and is equivalent to calling \fISDL_SetPalette\fR with the \fBflags\fR set to \fB(SDL_LOGPAL | SDL_PHYSPAL)\fP\&.
slouken@0
    18
.SH "RETURN VALUE"
slouken@0
    19
.PP
slouken@0
    20
If \fBsurface\fR is not a palettized surface, this function does nothing, returning \fB0\fR\&. If all of the colors were set as passed to \fBSDL_SetColors\fP, it will return \fB1\fR\&. If not all the color entries were set exactly as given, it will return \fB0\fR, and you should look at the surface palette to determine the actual color palette\&.
slouken@0
    21
.SH "EXAMPLE"
slouken@0
    22
.PP
slouken@0
    23
.nf
slouken@0
    24
\f(CW/* Create a display surface with a grayscale palette */
slouken@0
    25
SDL_Surface *screen;
slouken@0
    26
SDL_Color colors[256];
slouken@0
    27
int i;
slouken@0
    28
\&.
slouken@0
    29
\&.
slouken@0
    30
\&.
slouken@0
    31
/* Fill colors with color information */
slouken@0
    32
for(i=0;i<256;i++){
slouken@0
    33
  colors[i]\&.r=i;
slouken@0
    34
  colors[i]\&.g=i;
slouken@0
    35
  colors[i]\&.b=i;
slouken@0
    36
}
slouken@0
    37
slouken@0
    38
/* Create display */
slouken@0
    39
screen=SDL_SetVideoMode(640, 480, 8, SDL_HWPALETTE);
slouken@0
    40
if(!screen){
slouken@0
    41
  printf("Couldn\&'t set video mode: %s
slouken@0
    42
", SDL_GetError());
slouken@0
    43
  exit(-1);
slouken@0
    44
}
slouken@0
    45
slouken@0
    46
/* Set palette */
slouken@0
    47
SDL_SetColors(screen, colors, 0, 256);
slouken@0
    48
\&.
slouken@0
    49
\&.
slouken@0
    50
\&.
slouken@0
    51
\&.\fR
slouken@0
    52
.fi
slouken@0
    53
.PP
slouken@0
    54
.SH "SEE ALSO"
slouken@0
    55
.PP
slouken@0
    56
\fI\fBSDL_Color\fR\fR \fI\fBSDL_Surface\fR\fR, \fI\fBSDL_SetPalette\fP\fR, \fI\fBSDL_SetVideoMode\fP\fR
slouken@181
    57
...\" created by instant / docbook-to-man, Tue 11 Sep 2001, 23:01