1SDL_CreateRGBSurface(3)        SDL API Reference       SDL_CreateRGBSurface(3)
2
3
4

NAME

6       SDL_CreateRGBSurface- Create an empty SDL_Surface
7

SYNOPSIS

9       #include "SDL.h"
10
11       SDL_Surface  *SDL_CreateRGBSurface(Uint32 flags, int width, int height,
12       int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
13

DESCRIPTION

15       Allocate an empty surface (must be called after SDL_SetVideoMode)
16
17       If depth is 8 bits an empty palette is allocated for the surface,  oth‐
18       erwise   a   'packed-pixel'   SDL_PixelFormat   is  created  using  the
19       [RGBA]mask's provided (see SDL_PixelFormat). The  flags  specifies  the
20       type  of  surface  that should be created, it is an OR'd combination of
21       the following possible values.
22
23       SDL_SWSURFACE       SDL will create the surface in system memory.  This
24                           improves  the  performance  of  pixel level access,
25                           however you may not be able to  take  advantage  of
26                           some types of hardware blitting.
27
28       SDL_HWSURFACE       SDL  will  attempt  to  create the surface in video
29                           memory. This will allow SDL to  take  advantage  of
30                           Video->Video blits (which are often accelerated).
31
32       SDL_SRCCOLORKEY     This flag turns on colourkeying for blits from this
33                           surface. If SDL_HWSURFACE  is  also  specified  and
34                           colourkeyed  blits  are  hardware-accelerated, then
35                           SDL will attempt to place the surface in video mem‐
36                           ory.  Use SDL_SetColorKey to set or clear this flag
37                           after surface creation.
38
39       SDL_SRCALPHA        This flag turns on alpha-blending  for  blits  from
40                           this  surface.  If  SDL_HWSURFACE is also specified
41                           and alpha-blending blits are  hardware-accelerated,
42                           then  the surface will be placed in video memory if
43                           possible. Use SDL_SetAlpha to  set  or  clear  this
44                           flag after surface creation.
45
46              Note:
47
48              If an alpha-channel is specified (that is, if Amask is nonzero),
49              then the SDL_SRCALPHA flag is automatically set. You may  remove
50              this flag by calling SDL_SetAlpha after surface creation.
51

RETURN VALUE

53       Returns the created surface, or NULL upon error.
54

EXAMPLE

56           /* Create a 32-bit surface with the bytes of each pixel in R,G,B,A order,
57              as expected by OpenGL for textures */
58           SDL_Surface *surface;
59           Uint32 rmask, gmask, bmask, amask;
60
61           /* SDL interprets each pixel as a 32-bit number, so our masks must depend
62              on the endianness (byte order) of the machine */
63       #if SDL_BYTEORDER == SDL_BIG_ENDIAN
64           rmask = 0xff000000;
65           gmask = 0x00ff0000;
66           bmask = 0x0000ff00;
67           amask = 0x000000ff;
68       #else
69           rmask = 0x000000ff;
70           gmask = 0x0000ff00;
71           bmask = 0x00ff0000;
72           amask = 0xff000000;
73       #endif
74
75           surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
76                                          rmask, gmask, bmask, amask);
77           if(surface == NULL) {
78               fprintf(stderr, "CreateRGBSurface failed: %s
79       ", SDL_GetError());
80               exit(1);
81           }
82

SEE ALSO

84       SDL_CreateRGBSurfaceFrom,  SDL_FreeSurface, SDL_SetVideoMode, SDL_Lock‐
85       Surface, SDL_PixelFormat, SDL_Surface SDL_SetAlpha SDL_SetColorKey
86
87
88
89SDL                         Tue 11 Sep 2001, 23:01     SDL_CreateRGBSurface(3)
Impressum