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
flags | The 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
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
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
- Video needs
SDL_INIT_VIDEO, and sound needsSDL_INIT_AUDIO. SDL3 does not start the audio part for you.
In SDL2
The name is the same, but it returns 0 on success and a negative number on failure.