Wiki Page Content

Differences between revisions 3 and 4
Revision 3 as of 2016-10-15 02:32:19
Size: 1918
Editor: DanielG
Comment: clarify what the format argument is, link SDL_PixelFormatEnum there
Revision 4 as of 2016-10-15 02:44:43
Size: 1993
Editor: DanielG
Comment: copy & adapt code example from SDL_CreateRGBSurface()
Deletions are marked like this. Additions are marked like this.
Line 39: 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* surf;
    surf = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, SDL_PIXELFORMAT_RGBA32);
    if(surf == NULL) {
        fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
        exit(1);
    }
Line 41: Line 49:

##Leave this section as-is unless you have a code example to put in. In that case, replace You can add your code example here with your code example following the Style Guide instructions. Leave the rest of the markup alone and delete this comment.

DRAFT

SDL_CreateRGBSurfaceWithFormat

Use this function to allocate an RGB surface.

Syntax

SDL_Surface* SDL_CreateRGBSurfaceWithFormat(Uint32 flags,
                                            int    width,
                                            int    height,
                                            int    depth,
                                            Uint32 format)

Function Parameters

flags

the flags are obsolete and should be set to 0

width

the width in pixels of the surface to create

height

the height in pixels of the surface to create

depth

the depth in bits of the surface to create

format

the pixel format of the surface to create

Return Value

Returns a new SDL_Surface on success or NULL on failure; call SDL_GetError() for more information.

Code Examples

    /* 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* surf;
    surf = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, SDL_PIXELFORMAT_RGBA32);
    if(surf == NULL) {
        fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
        exit(1);
    }

Remarks

If the function runs out of memory, it will return NULL.

Version

This function is available since SDL 2.0.5.


CategoryAPI, CategorySurface

None: SDL_CreateRGBSurfaceWithFormat (last edited 2016-10-20 20:43:22 by PhilippWiesemann)

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