Wiki Page Content

Differences between revisions 3 and 5 (spanning 2 versions)
Revision 3 as of 2010-02-28 06:11:05
Size: 1890
Editor: SheenaSmith
Comment: minor change
Revision 5 as of 2010-08-08 23:59:03
Size: 3144
Editor: SheenaSmith
Comment: update content (old wiki)
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
Use this function to allocate ,,and free,, an RGB surface (must be called after [[SDL_SetVideoMode]]()).  <<Color2(green,where is info on Set``Video``Mode?)>> Use this function to allocate ,,and free,, an RGB surface.
Line 23: Line 23:
<<Color2(green,should flags be gray?)>> <<Color2(green,Should flags be gray? Why is there so much reference to '''flags''' if they're obsolete? (See below and [[SDL_ConvertSurface]] for example.))>>
Line 37: Line 37:
<<Color2(green,The following code example is from the old wiki but the params are no longer exactly the same. Should it be removed or updated?)>>
Line 38: Line 39:
You can add your code example here     /* 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);
    }

    /* or using the default masks for the depth: */
    surface=SDL_CreateRGBSurface(SDL_SWSURFACE,width,height,32,0,0,0,0);
Line 42: Line 70:
If ,,the,, '''depth''' is 4 or 8 bits, an empty palette is allocated for the surface. If ,,the,, '''depth''' is greater than 8 bits, the pixel format is set using the flags '[RGB]mask'. <<Color2(green,should it say flags or flag since there's only one listed?)>> If ,,the,, '''depth''' is 4 or 8 bits, an empty palette is allocated for the surface. If ,,the,, '''depth''' is greater than 8 bits, the pixel format is set using the '''flags''' '[RGB]mask'.

<<Color2(green,There is a lot of extra info in the old wiki but most relates to '''flags'''. Should any of it be transferred here?)>>
Line 45: Line 75:
 .[[SDL_ConvertSurface]] ???
Line 47: Line 78:
 .[[SDL_LockSurface]] *
 .[[SDL_SetColorKey]] *

DRAFT

SDL_CreateRGBSurface

Use this function to allocate and free an RGB surface.

Syntax

SDL_Surface* SDL_CreateRGBSurface (Uint32 flags,
                                   int    width,
                                   int    height,
                                   int    depth,
                                   Uint32 Rmask,
                                   Uint32 Gmask,
                                   Uint32 Bmask,
                                   Uint32 Amask)

Function Parameters

green

flags

the flags are obsolete and should be set to 0

width

the width of the surface

height

the height of the surface

depth

the depth of the surface in bits; see Remarks for details

Rmask

the red mask for the pixels

Gmask

the green mask for the pixels

Bmask

the blue mask for the pixels

Amask

the alpha mask for the pixels

Return Value

A pointer to an SDL_Surface to be created. If the function runs out of memory, it will return NULL.

Code Examples

green

    /* 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);
    }

    /* or using the default masks for the depth: */
    surface=SDL_CreateRGBSurface(SDL_SWSURFACE,width,height,32,0,0,0,0);

Remarks

If the depth is 4 or 8 bits, an empty palette is allocated for the surface. If the depth is greater than 8 bits, the pixel format is set using the flags '[RGB]mask'.

green


CategoryAPI, CategorySurface

None: SDL_CreateRGBSurface (last edited 2016-10-20 20:36:00 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit