SDL_DisplayFormat -- Convert a surface to the display format


#include "SDL.h"

SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface);


This function takes a surface and copies it to a new surface of the pixel format and colors of the video framebuffer, suitable for fast blitting onto the display surface. It calls SDL_ConvertSurface.

If you want to take advantage of hardware colorkey or alpha blit acceleration, you should set the colorkey and alpha value before calling this function.

If you want an alpha channel, see SDL_DisplayFormatAlpha.

Return Value

If the conversion fails or runs out of memory, it returns NULL

Newbie hint

You have to call SDL_Init before using the SDL_DisplayFormat function. If you don't, your program will crash with an access violation.

Remember to use a different variable for the returned surface, otherwise you have a memory leak, since the original surface isn't freed.

surface = SDL_DisplayFormat(surface);  // memory leak!!

// correct version
NewSurface = SDL_DisplayFormat(surface);

See Also

SDL_ConvertSurface, SDL_DisplayFormatAlpha, SDL_SetAlpha, SDL_SetColorKey, SDL_Surface

SDL_DisplayFormat (last edited 2008-04-17 08:18:17 by localhost)