[Prev] Table Of Contents [Next]

Using the Simple DirectMedia Layer API

Initializing the library

Use SDL_Init() to dynamically load and initialize the library. This function takes a set of flags corresponding to the portions you want to activate:

SDL_INIT_AUDIO
SDL_INIT_VIDEO
SDL_INIT_CDROM
SDL_INIT_TIMER

Use SDL_Quit() to clean up the library when you are done with it.

Tip:
SDL dynamically loads the SDL library from the standard system library locations. Use the SDL_SetLibraryPath() function to use an alternate location for the dynamic libraries distributed with your application.
Example:
#include <stdlib.h>
#include "SDL.h"

main(int argc, char *argv[])
{
    if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }
    atexit(SDL_Quit);

    ...
}

[Prev] Table Of Contents [Next]