📄 sdlcreatergbsurface.html
字号:
<HTML><HEAD><TITLE>SDL_CreateRGBSurface</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_GetRGBA"HREF="sdlgetrgba.html"><LINKREL="NEXT"TITLE="SDL_CreateRGBSurfaceFrom"HREF="sdlcreatergbsurfacefrom.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="sdlgetrgba.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sdlcreatergbsurfacefrom.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="SDLCREATERGBSURFACE"></A>SDL_CreateRGBSurface</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN1773"></A><H2>Name</H2>SDL_CreateRGBSurface -- Create an empty SDL_Surface</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN1776"></A><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN1777"></A><P></P><PRECLASS="FUNCSYNOPSISINFO">#include "SDL.h"</PRE><P><CODE><CODECLASS="FUNCDEF">SDL_Surface *<BCLASS="FSFUNC">SDL_CreateRGBSurface</B></CODE>(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN1783"></A><H2>Description</H2><P>Allocate an empty surface (must be called after <AHREF="sdlsetvideomode.html">SDL_SetVideoMode</A>)</P><P>If <TTCLASS="PARAMETER"><I>depth</I></TT> is 8 bits an empty palette is allocated for the surface, otherwise a 'packed-pixel' <AHREF="sdlpixelformat.html"><SPANCLASS="STRUCTNAME">SDL_PixelFormat</SPAN></A> is created using the <TTCLASS="PARAMETER"><I>[RGBA]mask</I></TT>'s provided (see <AHREF="sdlpixelformat.html"><SPANCLASS="STRUCTNAME">SDL_PixelFormat</SPAN></A>). The <TTCLASS="PARAMETER"><I>flags</I></TT> specifies the type of surface that should be created, it is an OR'd combination of the following possible values.</P><DIVCLASS="INFORMALTABLE"><ANAME="AEN1795"></A><P></P><TABLEBORDER="1"CLASS="CALSTABLE"><TBODY><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="LITERAL">SDL_SWSURFACE</TT></TD><TDALIGN="LEFT"VALIGN="TOP">SDL will create the surface in system memory. This improves the performance of pixel level access, however you may not be able to take advantage of some types of hardware blitting.</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="LITERAL">SDL_HWSURFACE</TT></TD><TDALIGN="LEFT"VALIGN="TOP">SDL will attempt to create the surface in video memory. This will allow SDL to take advantage of Video->Video blits (which are often accelerated).</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="LITERAL">SDL_SRCCOLORKEY</TT></TD><TDALIGN="LEFT"VALIGN="TOP">This flag turns on colourkeying for blits from this surface. If<TTCLASS="LITERAL">SDL_HWSURFACE</TT> is also specified and colourkeyed blitsare hardware-accelerated, then SDL will attempt to place the surface invideo memory.Use <AHREF="sdlsetcolorkey.html"><TTCLASS="FUNCTION">SDL_SetColorKey</TT></A>to set or clear this flag after surface creation.</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="LITERAL">SDL_SRCALPHA</TT></TD><TDALIGN="LEFT"VALIGN="TOP">This flag turns on alpha-blending for blits from this surface. If<TTCLASS="LITERAL">SDL_HWSURFACE</TT> is also specified and alpha-blending blitsare hardware-accelerated, then the surface will be placed in video memory ifpossible.Use <AHREF="sdlsetalpha.html"><TTCLASS="FUNCTION">SDL_SetAlpha</TT></A> toset or clear this flag after surface creation.</TD></TR></TBODY></TABLE><P></P></DIV><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>If an alpha-channel is specified (that is, if <TTCLASS="PARAMETER"><I>Amask</I></TT> isnonzero), then the <TTCLASS="LITERAL">SDL_SRCALPHA</TT> flag is automaticallyset. You may remove this flag by calling <AHREF="sdlsetalpha.html"><TTCLASS="FUNCTION">SDL_SetAlpha</TT></A>after surface creation.</P></BLOCKQUOTE></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN1826"></A><H2>Return Value</H2><P>Returns the created surface, or <SPANCLASS="RETURNVALUE">NULL</SPAN> upon error.</P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN1830"></A><H2>Example</H2><PRECLASS="PROGRAMLISTING"> /* Create a 32-bit surface with the bytes of each pixel in R,G,B,A order, as expected by OpenGL for textures */ SDL_Surface *surface; Uint32 rmask, gmask, bmask, amask; /* SDL interprets each pixel as a 32-bit number, so our masks must depend on the endianness (byte order) of the machine */#if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff;#else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000;#endif surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, rmask, gmask, bmask, amask); if(surface == NULL) { fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError()); exit(1); }</PRE></DIV><DIVCLASS="REFSECT1"><ANAME="AEN1833"></A><H2>See Also</H2><P><AHREF="sdlcreatergbsurfacefrom.html"><TTCLASS="FUNCTION">SDL_CreateRGBSurfaceFrom</TT></A>,<AHREF="sdlfreesurface.html"><TTCLASS="FUNCTION">SDL_FreeSurface</TT></A>,<AHREF="sdlsetvideomode.html"><TTCLASS="FUNCTION">SDL_SetVideoMode</TT></A>,<AHREF="sdllocksurface.html"><TTCLASS="FUNCTION">SDL_LockSurface</TT></A>,<AHREF="sdlpixelformat.html"><SPANCLASS="STRUCTNAME">SDL_PixelFormat</SPAN></A>,<AHREF="sdlsurface.html"><SPANCLASS="STRUCTNAME">SDL_Surface</SPAN></A><AHREF="sdlsetalpha.html"><TTCLASS="FUNCTION">SDL_SetAlpha</TT></A><AHREF="sdlsetcolorkey.html"><TTCLASS="FUNCTION">SDL_SetColorKey</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="sdlgetrgba.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="sdlcreatergbsurfacefrom.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">SDL_GetRGBA</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="video.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">SDL_CreateRGBSurfaceFrom</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -