📄 sdlsetcolors.html
字号:
<HTML><HEAD><TITLE>SDL_SetColors</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="SDL Library Documentation"HREF="index.html"><LINKREL="UP"TITLE="Video"HREF="video.html"><LINKREL="PREVIOUS"TITLE="SDL_Flip"HREF="sdlflip.html"><LINKREL="NEXT"TITLE="SDL_SetPalette"HREF="sdlsetpalette.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFF8DC"TEXT="#000000"LINK="#0000ee"VLINK="#551a8b"ALINK="#ff0000"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">SDL Library Documentation</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sdlflip.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sdlsetpalette.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="SDLSETCOLORS"></A>SDL_SetColors</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN1462"></A><H2>Name</H2>SDL_SetColors -- Sets a portion of the colormap for the given 8-bit surface.</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN1465"></A><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN1466"></A><P></P><PRECLASS="FUNCSYNOPSISINFO">#include "SDL.h"</PRE><P><CODE><CODECLASS="FUNCDEF">int <BCLASS="FSFUNC">SDL_SetColors</B></CODE>(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors);</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN1472"></A><H2>Description</H2><P>Sets a portion of the colormap for the given 8-bit surface.</P><P>When <TTCLASS="PARAMETER"><I>surface</I></TT> is the surface associated with the currentdisplay, the display colormap will be updated with the requested colors. If<TTCLASS="LITERAL">SDL_HWPALETTE</TT> was set in <AHREF="sdlsetvideomode.html">SDL_SetVideoMode</A> flags,<TTCLASS="FUNCTION">SDL_SetColors</TT> will always return <SPANCLASS="RETURNVALUE">1</SPAN>,and the palette is guaranteed to be set the way you desire, even if the windowcolormap has to be warped or run under emulation.</P><P>The color components of a<AHREF="sdlcolor.html"><SPANCLASS="STRUCTNAME">SDL_Color</SPAN></A>structure are 8-bits in size, giving you a total of 256<SUP>3</SUP>=16777216 colors.</P><P>Palettized (8-bit) screen surfaces with the <TTCLASS="LITERAL">SDL_HWPALETTE</TT>flag have two palettes, a logical palette that is used for mapping blitsto/from the surface and a physical palette (that determines how thehardware will map the colors to the display). <TTCLASS="FUNCTION">SDL_SetColors</TT>modifies both palettes (if present), and is equivalent to calling<AHREF="sdlsetpalette.html">SDL_SetPalette</A> with the<TTCLASS="PARAMETER"><I>flags</I></TT> set to<TTCLASS="LITERAL">(SDL_LOGPAL | SDL_PHYSPAL)</TT>.</P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN1491"></A><H2>Return Value</H2><P>If <TTCLASS="PARAMETER"><I>surface</I></TT> is not a palettized surface, this functiondoes nothing, returning <SPANCLASS="RETURNVALUE">0</SPAN>. If all of the colors were setas passed to <TTCLASS="FUNCTION">SDL_SetColors</TT>, it will return<SPANCLASS="RETURNVALUE">1</SPAN>. If not all the color entries were set exactly asgiven, it will return <SPANCLASS="RETURNVALUE">0</SPAN>, and you should look at thesurface palette to determine the actual color palette.</P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN1499"></A><H2>Example</H2><PRECLASS="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_SetColors(screen, colors, 0, 256);....</PRE></DIV><DIVCLASS="REFSECT1"><ANAME="AEN1502"></A><H2>See Also</H2><P><AHREF="sdlcolor.html"><SPANCLASS="STRUCTNAME">SDL_Color</SPAN></A><AHREF="sdlsurface.html"><SPANCLASS="STRUCTNAME">SDL_Surface</SPAN></A>,<AHREF="sdlsetpalette.html"><TTCLASS="FUNCTION">SDL_SetPalette</TT></A>,<AHREF="sdlsetvideomode.html"><TTCLASS="FUNCTION">SDL_SetVideoMode</TT></A></P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="sdlflip.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="index.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="sdlsetpalette.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">SDL_Flip</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="video.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">SDL_SetPalette</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -