SDL Library Documentation
Prev |  | Next

# Chapter 6. Video

SDL presents a very simple interface to the display framebuffer. The framebuffer is represented as an offscreen surface to which you can write directly. If you want the screen to show what you have written, call the update function which will guarantee that the desired portion of the screen is updated.

Before you call any of the SDL video functions, you must first call SDL_Init(SDL_INIT_VIDEO), which initializes the video and events in the SDL library. Check the return code, which should be 0, to see if there were any errors in starting up.

If you use both sound and video in your application, you need to call SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO) before opening the sound device, otherwise under Win32 DirectX, you won't be able to set full-screen display modes.

After you have initialized the library, you can start up the video display in a number of ways. The easiest way is to pick a common screen resolution and depth and just initialize the video, checking for errors. You will probably get what you want, but SDL may be emulating your requested mode and converting the display on update. The best way is to query, for the best video mode closest to the desired one, and then convert your images to that pixel format.

SDL currently supports any bit depth >= 8 bits per pixel. 8 bpp formats are considered 8-bit palettized modes, while 12, 15, 16, 24, and 32 bits per pixel are considered "packed pixel" modes, meaning each pixel contains the RGB color components packed in the bits of the pixel.

After you have initialized your video mode, you can take the surface that was returned, and write to it like any other framebuffer, calling the update routine as you go.

When you have finished your video access and are ready to quit your application, you should call "SDL_Quit()" to shutdown the video and events.

Prev | Home | Next
SDL_envvars | Up | SDL_GetVideoSurface