SDL School

API reference / Application

SDL_Init

Function, SDL3

Starts the parts of SDL that your program needs. Call it before most other SDL functions.

Declaration

#include <SDL3/SDL.h>

bool SDL_Init(SDL_InitFlags flags);

Parameters

flagsThe parts to start. Join them with |, for example SDL_INIT_VIDEO | SDL_INIT_AUDIO.

Return value

True on success. On failure it returns false, and SDL_GetError gives the reason.

Example

Open a window
if (!SDL_Init(SDL_INIT_VIDEO)) {
    SDL_Log("SDL_Init failed: %s", SDL_GetError());
    return SDL_APP_FAILURE;
}

See this code run in Open a window. Download the full program (.zip)

In Play a sound

Play a sound
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
    SDL_Log("SDL_Init failed: %s", SDL_GetError());
    return SDL_APP_FAILURE;
}

See this code run in Play a sound. Download the full program (.zip)

Notes

In SDL2

The name is the same, but it returns 0 on success and a negative number on failure.

See also