sdlsetpalette.html

来自「VC5.6.7的一个扩展库。跟DirectX的功能差不多。」· HTML 代码 · 共 352 行

HTML
352
字号
<HTML><HEAD><TITLE>SDL_SetPalette</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_SetColors"HREF="sdlsetcolors.html"><LINKREL="NEXT"TITLE="SDL_SetGamma"HREF="sdlsetgamma.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="sdlsetcolors.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sdlsetgamma.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="SDLSETPALETTE"></A>SDL_SetPalette</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN1517"></A><H2>Name</H2>SDL_SetPalette&nbsp;--&nbsp;Sets the colors in the palette of an 8-bit surface.</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN1520"></A><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN1521"></A><P></P><PRECLASS="FUNCSYNOPSISINFO">#include "SDL.h"</PRE><P><CODE><CODECLASS="FUNCDEF">int <BCLASS="FSFUNC">SDL_SetPalette</B></CODE>(SDL_Surface *surface, int flags, SDL_Color *colors, int firstcolor, int ncolors);</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN1527"></A><H2>Description</H2><P>Sets a portion of the palette for the given 8-bit surface.</P><P>Palettized (8-bit) screen surfaces with the<TTCLASS="LITERAL">SDL_HWPALETTE</TT> flag have two palettes, a logicalpalette that is used for mapping blits to/from the surface and aphysical palette (that determines how the hardware will map the colorsto the display). <AHREF="sdlblitsurface.html">SDL_BlitSurface</A>always uses the logical palette when blitting surfaces (if it has toconvert between surface pixel formats). Because of this, it is oftenuseful to modify only one or the other palette to achieve variousspecial color effects (e.g., screen fading, color flashes, screen dimming).</P><P>This function can modify either the logical or physical palette byspecifing <TTCLASS="LITERAL">SDL_LOGPAL</TT> or<TTCLASS="LITERAL">SDL_PHYSPAL</TT>the in the <TTCLASS="PARAMETER"><I>flags</I></TT>parameter.</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_SetPalette</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> structureare 8-bits in size, giving you a total of256<SUP>3</SUP>=16777216 colors.</P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN1547"></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_SetPalette</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="AEN1555"></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&#60;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);        .        .        .        .</PRE></DIV><DIVCLASS="REFSECT1"><ANAME="AEN1558"></A><H2>See Also</H2><P><AHREF="sdlsetcolors.html">SDL_SetColors</A>,<AHREF="sdlsetvideomode.html">SDL_SetVideoMode</A>,<AHREF="sdlsurface.html">SDL_Surface</A>,<AHREF="sdlcolor.html">SDL_Color</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="sdlsetcolors.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="sdlsetgamma.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">SDL_SetColors</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="video.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">SDL_SetGamma</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?