SDL.h File Reference
`#include "SDL_main.h"`
`#include "SDL_stdinc.h"`
`#include "SDL_assert.h"`
`#include "SDL_atomic.h"`
`#include "SDL_audio.h"`
`#include "SDL_clipboard.h"`
`#include "SDL_cpuinfo.h"`
`#include "SDL_endian.h"`
`#include "SDL_error.h"`
`#include "SDL_events.h"`
`#include "SDL_filesystem.h"`
`#include "SDL_joystick.h"`
`#include "SDL_gamecontroller.h"`
`#include "SDL_haptic.h"`
`#include "SDL_hints.h"`
`#include "SDL_loadso.h"`
`#include "SDL_log.h"`
`#include "SDL_messagebox.h"`
`#include "SDL_mutex.h"`
`#include "SDL_power.h"`
`#include "SDL_render.h"`
`#include "SDL_rwops.h"`
`#include "SDL_system.h"`
`#include "SDL_thread.h"`
`#include "SDL_timer.h"`
`#include "SDL_version.h"`
`#include "SDL_video.h"`
`#include "begin_code.h"`
`#include "close_code.h"`
Include dependency graph for SDL.h:

Go to the source code of this file.

## Macros

SDL_INIT_*
These are the flags which may be passed to SDL_Init(). You should specify the subsystems which you will be using in your application.
#define | SDL_INIT_TIMER 0x00000001
#define | SDL_INIT_AUDIO 0x00000010
#define | SDL_INIT_VIDEO 0x00000020
#define | SDL_INIT_JOYSTICK 0x00000200
#define | SDL_INIT_HAPTIC 0x00001000
#define | SDL_INIT_GAMECONTROLLER 0x00002000
#define | SDL_INIT_EVENTS 0x00004000
#define | SDL_INIT_NOPARACHUTE 0x00100000
#define | SDL_INIT_EVERYTHING

## Functions

int | SDL_Init (Uint32 flags)
int | SDL_InitSubSystem (Uint32 flags)
void | SDL_QuitSubSystem (Uint32 flags)
Uint32 | SDL_WasInit (Uint32 flags)
void | SDL_Quit (void)

## Detailed Description

Main include header for the SDL library

Definition in file SDL.h.

## Macro Definition Documentation

#define SDL_INIT_AUDIO 0x00000010

Definition at line 76 of file SDL.h.

Referenced by _audioSetUp(), audio_initOpenCloseQuitAudio(), audio_initQuitAudio(), audio_pauseUnpauseAudio(), audio_quitInitAudioSubSystem(), main(), open_audio_device(), SDL_AudioInit(), SDL_GetAudioDeviceName(), SDL_GetNumAudioDevices(), SDL_InitSubSystem(), SDL_OpenAudio(), SDL_QuitSubSystem(), SDLTest_CommonInit(), SDLTest_CommonQuit(), and SDLTest_CommonUsage().

#define SDL_INIT_EVENTS 0x00004000

Definition at line 81 of file SDL.h.

Referenced by SDL_InitSubSystem(), SDL_JoystickInit(), SDL_JoystickQuit(), SDL_QuitSubSystem(), SDL_VideoInit(), and SDL_VideoQuit().

#define SDL_INIT_EVERYTHING

Value:
( \
SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \
)
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:81
SDL_INIT_JOYSTICK
#define SDL_INIT_JOYSTICK
Definition: SDL.h:78
SDL_INIT_TIMER
#define SDL_INIT_TIMER
Definition: SDL.h:75
SDL_INIT_AUDIO
#define SDL_INIT_AUDIO
Definition: SDL.h:76
SDL_INIT_GAMECONTROLLER
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:80
SDL_INIT_HAPTIC
#define SDL_INIT_HAPTIC
Definition: SDL.h:79
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:77

Definition at line 83 of file SDL.h.

Referenced by platform_testDefaultInit(), SDL_Quit(), and SDL_WasInit().

#define SDL_INIT_GAMECONTROLLER 0x00002000

SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK

Definition at line 80 of file SDL.h.

Referenced by main(), main_testImpliedJoystickInit(), main_testImpliedJoystickQuit(), main_testInitQuitSubSystem(), SDL_InitSubSystem(), and SDL_QuitSubSystem().

#define SDL_INIT_HAPTIC 0x00001000

Definition at line 79 of file SDL.h.

Referenced by main(), main_testInitQuitJoystickHaptic(), main_testInitQuitSubSystem(), SDL_InitSubSystem(), and SDL_QuitSubSystem().

#define SDL_INIT_JOYSTICK 0x00000200

SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS

Definition at line 78 of file SDL.h.

Referenced by main(), main_testImpliedJoystickQuit(), main_testInitQuitJoystickHaptic(), main_testInitQuitSubSystem(), SDL_InitSubSystem(), and SDL_QuitSubSystem().

#define SDL_INIT_NOPARACHUTE 0x00100000

compatibility; this flag is ignored.

Definition at line 82 of file SDL.h.

#define SDL_INIT_TIMER 0x00000001

Definition at line 75 of file SDL.h.

Referenced by _timerSetUp(), main(), SDL_InitSubSystem(), SDL_QuitSubSystem(), and SDLTest_SetTestTimeout().

#define SDL_INIT_VIDEO 0x00000020

SDL_INIT_VIDEO implies SDL_INIT_EVENTS

Definition at line 77 of file SDL.h.

Referenced by main(), SDL_InitSubSystem(), SDL_PrivateJoystickShouldIgnoreEvent(), SDL_QuitSubSystem(), SDL_WinRTInitXAMLApp(), SDLTest_CommonInit(), SDLTest_CommonQuit(), and SDLTest_CommonUsage().

## Function Documentation

int SDL_Init | ( | Uint32 | flags | ) |

This function initializes the subsystems specified by `flags`

Definition at line 242 of file SDL.c.

References SDL_InitSubSystem().

{
return SDL_InitSubSystem(flags);
}
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
SDL_InitSubSystem
int SDL_InitSubSystem(Uint32 flags)
Definition: SDL.c:108

int SDL_InitSubSystem | ( | Uint32 | flags | ) |

This function initializes specific SDL subsystems

Subsystem initialization is ref-counted, you must call SDL_QuitSubSystem for each SDL_InitSubSystem to correctly shutdown a subsystem manually (or call SDL_Quit to force shutdown). If a subsystem is already loaded then this call will increase the ref-count and return.

Definition at line 108 of file SDL.c.

References NULL, SDL_AudioInit, SDL_ClearError, SDL_GameControllerInit(), SDL_HapticInit(), SDL_INIT_AUDIO, SDL_INIT_EVENTS, SDL_INIT_GAMECONTROLLER, SDL_INIT_HAPTIC, SDL_INIT_JOYSTICK, SDL_INIT_TIMER, SDL_INIT_VIDEO, SDL_JoystickInit(), SDL_MainIsReady, SDL_PrivateShouldInitSubsystem(), SDL_PrivateSubsystemRefCountIncr(), SDL_QuitInit(), SDL_SetError, SDL_StartEventLoop(), SDL_TicksInit(), SDL_TimerInit(), and SDL_VideoInit.

Referenced by SDL_Init().

{
if (!SDL_MainIsReady) {
SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
return -1;
}
/* Clear the error message */
SDL_ClearError();
#if SDL_VIDEO_DRIVER_WINDOWS
if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) {
if (SDL_HelperWindowCreate() < 0) {
return -1;
}
}
#endif
#if !SDL_TIMERS_DISABLED
SDL_TicksInit();
#endif
if ((flags & SDL_INIT_GAMECONTROLLER)) {
/* game controller implies joystick */
flags |= SDL_INIT_JOYSTICK;
}
if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))) {
/* video or joystick implies events */
flags |= SDL_INIT_EVENTS;
}
/* Initialize the event subsystem */
if ((flags & SDL_INIT_EVENTS)) {
#if !SDL_EVENTS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
if (SDL_StartEventLoop() < 0) {
return (-1);
}
SDL_QuitInit();
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
#else
return SDL_SetError("SDL not built with events support");
#endif
}
/* Initialize the timer subsystem */
if ((flags & SDL_INIT_TIMER)){
#if !SDL_TIMERS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
if (SDL_TimerInit() < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
#else
return SDL_SetError("SDL not built with timer support");
#endif
}
/* Initialize the video subsystem */
if ((flags & SDL_INIT_VIDEO)){
#if !SDL_VIDEO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
if (SDL_VideoInit(NULL) < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
#else
return SDL_SetError("SDL not built with video support");
#endif
}
/* Initialize the audio subsystem */
if ((flags & SDL_INIT_AUDIO)){
#if !SDL_AUDIO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
if (SDL_AudioInit(NULL) < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
#else
return SDL_SetError("SDL not built with audio support");
#endif
}
/* Initialize the joystick subsystem */
if ((flags & SDL_INIT_JOYSTICK)){
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
if (SDL_JoystickInit() < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
#else
return SDL_SetError("SDL not built with joystick support");
#endif
}
if ((flags & SDL_INIT_GAMECONTROLLER)){
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
if (SDL_GameControllerInit() < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
#else
return SDL_SetError("SDL not built with joystick support");
#endif
}
/* Initialize the haptic subsystem */
if ((flags & SDL_INIT_HAPTIC)){
#if !SDL_HAPTIC_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
if (SDL_HapticInit() < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
#else
return SDL_SetError("SDL not built with haptic (force feedback) support");
#endif
}
return (0);
}
SDL_ClearError
#define SDL_ClearError
Definition: SDL_dynapi_overrides.h:120
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:81
SDL_MainIsReady
static SDL_bool SDL_MainIsReady
Definition: SDL.c:54
SDL_INIT_JOYSTICK
#define SDL_INIT_JOYSTICK
Definition: SDL.h:78
SDL_AudioInit
#define SDL_AudioInit
Definition: SDL_dynapi_overrides.h:81
SDL_JoystickInit
int SDL_JoystickInit(void)
Definition: SDL_joystick.c:50
SDL_StartEventLoop
int SDL_StartEventLoop(void)
Definition: SDL_events.c:160
SDL_QuitInit
int SDL_QuitInit(void)
Definition: SDL_quit.c:92
SDL_PrivateSubsystemRefCountIncr
static void SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
Definition: SDL.c:61
SDL_VideoInit
#define SDL_VideoInit
Definition: SDL_dynapi_overrides.h:502
NULL
#define NULL
Definition: begin_code.h:143
SDL_PrivateShouldInitSubsystem
static SDL_bool SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
Definition: SDL.c:80
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
SDL_INIT_TIMER
#define SDL_INIT_TIMER
Definition: SDL.h:75
SDL_INIT_AUDIO
#define SDL_INIT_AUDIO
Definition: SDL.h:76
SDL_TicksInit
void SDL_TicksInit(void)
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
SDL_INIT_GAMECONTROLLER
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:80
SDL_INIT_HAPTIC
#define SDL_INIT_HAPTIC
Definition: SDL.h:79
SDL_GameControllerInit
int SDL_GameControllerInit(void)
Definition: SDL_gamecontroller.c:860
SDL_HapticInit
int SDL_HapticInit(void)
Definition: SDL_haptic.c:35
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:77
SDL_TimerInit
int SDL_TimerInit(void)
Definition: SDL_timer.c:206

void SDL_Quit | ( | void |  | ) |

This function cleans up all initialized subsystems. You should call it upon all exit conditions.

Definition at line 349 of file SDL.c.

References SDL_AssertionsQuit(), SDL_bInMainQuit, SDL_ClearHints, SDL_FALSE, SDL_INIT_EVERYTHING, SDL_LogResetPriorities, SDL_memset, SDL_QuitSubSystem(), SDL_SubsystemRefCount, SDL_TicksQuit(), and SDL_TRUE.

{
SDL_bInMainQuit = SDL_TRUE;
/* Quit all subsystems */
#if SDL_VIDEO_DRIVER_WINDOWS
SDL_HelperWindowDestroy();
#endif
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
#if !SDL_TIMERS_DISABLED
SDL_TicksQuit();
#endif
SDL_ClearHints();
SDL_AssertionsQuit();
SDL_LogResetPriorities();
/* Now that every subsystem has been quit, we reset the subsystem refcount
* and the list of initialized subsystems.
*/
SDL_memset( SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount) );
SDL_bInMainQuit = SDL_FALSE;
}
SDL_LogResetPriorities
#define SDL_LogResetPriorities
Definition: SDL_dynapi_overrides.h:244
SDL_SubsystemRefCount
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:57
SDL_QuitSubSystem
void SDL_QuitSubSystem(Uint32 flags)
Definition: SDL.c:248
SDL_ClearHints
#define SDL_ClearHints
Definition: SDL_dynapi_overrides.h:200
SDL_bInMainQuit
static SDL_bool SDL_bInMainQuit
Definition: SDL.c:56
SDL_TicksQuit
void SDL_TicksQuit(void)
SDL_AssertionsQuit
void SDL_AssertionsQuit(void)
Definition: SDL_assert.c:332
SDL_INIT_EVERYTHING
#define SDL_INIT_EVERYTHING
Definition: SDL.h:83
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128
x0
GLuint GLfloat x0
Definition: SDL_opengl_glext.h:8583
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:392

void SDL_QuitSubSystem | ( | Uint32 | flags | ) |

This function cleans up specific SDL subsystems

Definition at line 248 of file SDL.c.

References SDL_AudioQuit, SDL_GameControllerQuit(), SDL_HapticQuit(), SDL_INIT_AUDIO, SDL_INIT_EVENTS, SDL_INIT_GAMECONTROLLER, SDL_INIT_HAPTIC, SDL_INIT_JOYSTICK, SDL_INIT_TIMER, SDL_INIT_VIDEO, SDL_JoystickQuit(), SDL_PrivateShouldQuitSubsystem(), SDL_PrivateSubsystemRefCountDecr(), SDL_QuitQuit(), SDL_StopEventLoop(), SDL_TimerQuit(), and SDL_VideoQuit.

Referenced by SDL_Quit().

{
/* Shut down requested initialized subsystems */
#if !SDL_JOYSTICK_DISABLED
if ((flags & SDL_INIT_GAMECONTROLLER)) {
/* game controller implies joystick */
flags |= SDL_INIT_JOYSTICK;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
SDL_GameControllerQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
}
if ((flags & SDL_INIT_JOYSTICK)) {
/* joystick implies events */
flags |= SDL_INIT_EVENTS;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
SDL_JoystickQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_JOYSTICK);
}
#endif
#if !SDL_HAPTIC_DISABLED
if ((flags & SDL_INIT_HAPTIC)) {
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
SDL_HapticQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_HAPTIC);
}
#endif
#if !SDL_AUDIO_DISABLED
if ((flags & SDL_INIT_AUDIO)) {
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
SDL_AudioQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_AUDIO);
}
#endif
#if !SDL_VIDEO_DISABLED
if ((flags & SDL_INIT_VIDEO)) {
/* video implies events */
flags |= SDL_INIT_EVENTS;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
SDL_VideoQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_VIDEO);
}
#endif
#if !SDL_TIMERS_DISABLED
if ((flags & SDL_INIT_TIMER)) {
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
SDL_TimerQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
}
#endif
#if !SDL_EVENTS_DISABLED
if ((flags & SDL_INIT_EVENTS)) {
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
SDL_QuitQuit();
SDL_StopEventLoop();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
}
#endif
}
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:81
SDL_HapticQuit
void SDL_HapticQuit(void)
Definition: SDL_haptic.c:389
SDL_INIT_JOYSTICK
#define SDL_INIT_JOYSTICK
Definition: SDL.h:78
SDL_TimerQuit
void SDL_TimerQuit(void)
Definition: SDL_timer.c:246
SDL_AudioQuit
#define SDL_AudioQuit
Definition: SDL_dynapi_overrides.h:82
SDL_GameControllerQuit
void SDL_GameControllerQuit(void)
Definition: SDL_gamecontroller.c:1200
SDL_INIT_TIMER
#define SDL_INIT_TIMER
Definition: SDL.h:75
SDL_INIT_AUDIO
#define SDL_INIT_AUDIO
Definition: SDL.h:76
SDL_PrivateSubsystemRefCountDecr
static void SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
Definition: SDL.c:70
SDL_VideoQuit
#define SDL_VideoQuit
Definition: SDL_dynapi_overrides.h:503
SDL_PrivateShouldQuitSubsystem
static SDL_bool SDL_PrivateShouldQuitSubsystem(Uint32 subsystem)
Definition: SDL.c:89
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
SDL_INIT_GAMECONTROLLER
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:80
SDL_JoystickQuit
void SDL_JoystickQuit(void)
Definition: SDL_joystick.c:458
SDL_INIT_HAPTIC
#define SDL_INIT_HAPTIC
Definition: SDL.h:79
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:77
SDL_QuitQuit
void SDL_QuitQuit(void)
Definition: SDL_quit.c:130
SDL_StopEventLoop
void SDL_StopEventLoop(void)
Definition: SDL_events.c:90

Uint32 SDL_WasInit | ( | Uint32 | flags | ) |

This function returns a mask of the specified subsystems which have previously been initialized.

If `flags` is 0, it returns a mask of all initialized subsystems.

Definition at line 324 of file SDL.c.

References i, SDL_arraysize, SDL_INIT_EVERYTHING, SDL_min, SDL_MostSignificantBitIndex32(), and SDL_SubsystemRefCount.

{
int i;
int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
Uint32 initialized = 0;
if (!flags) {
flags = SDL_INIT_EVERYTHING;
}
num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
/* Iterate over each bit in flags, and check the matching subsystem. */
for (i = 0; i < num_subsystems; ++i) {
if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
initialized |= (1 << i);
}
flags >>= 1;
}
return initialized;
}
SDL_min
#define SDL_min(x, y)
Definition: SDL_stdinc.h:345
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
SDL_SubsystemRefCount
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:57
SDL_MostSignificantBitIndex32
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
Definition: SDL_bits.h:51
SDL_INIT_EVERYTHING
#define SDL_INIT_EVERYTHING
Definition: SDL.h:83
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480