SDL  2.0
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_gamecontroller.h"
#include "SDL_haptic.h"
#include "SDL_hints.h"
#include "SDL_joystick.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_sensor.h"
#include "SDL_shape.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.

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   0x00000001u
 
#define SDL_INIT_AUDIO   0x00000010u
 
#define SDL_INIT_VIDEO   0x00000020u
 
#define SDL_INIT_JOYSTICK   0x00000200u
 
#define SDL_INIT_HAPTIC   0x00001000u
 
#define SDL_INIT_GAMECONTROLLER   0x00002000u
 
#define SDL_INIT_EVENTS   0x00004000u
 
#define SDL_INIT_SENSOR   0x00008000u
 
#define SDL_INIT_NOPARACHUTE   0x00100000u
 
#define SDL_INIT_EVERYTHING
 
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

◆ SDL_INIT_AUDIO

#define SDL_INIT_AUDIO   0x00000010u

Definition at line 78 of file SDL.h.

◆ SDL_INIT_EVENTS

#define SDL_INIT_EVENTS   0x00004000u

Definition at line 83 of file SDL.h.

◆ SDL_INIT_EVERYTHING

#define SDL_INIT_EVERYTHING
Value:
( \
)

Definition at line 86 of file SDL.h.

◆ SDL_INIT_GAMECONTROLLER

#define SDL_INIT_GAMECONTROLLER   0x00002000u

SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK

Definition at line 82 of file SDL.h.

◆ SDL_INIT_HAPTIC

#define SDL_INIT_HAPTIC   0x00001000u

Definition at line 81 of file SDL.h.

◆ SDL_INIT_JOYSTICK

#define SDL_INIT_JOYSTICK   0x00000200u

SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS

Definition at line 80 of file SDL.h.

◆ SDL_INIT_NOPARACHUTE

#define SDL_INIT_NOPARACHUTE   0x00100000u

compatibility; this flag is ignored.

Definition at line 85 of file SDL.h.

◆ SDL_INIT_SENSOR

#define SDL_INIT_SENSOR   0x00008000u

Definition at line 84 of file SDL.h.

◆ SDL_INIT_TIMER

#define SDL_INIT_TIMER   0x00000001u

Definition at line 77 of file SDL.h.

◆ SDL_INIT_VIDEO

#define SDL_INIT_VIDEO   0x00000020u

SDL_INIT_VIDEO implies SDL_INIT_EVENTS

Definition at line 79 of file SDL.h.

Function Documentation

◆ SDL_Init()

int SDL_Init ( Uint32  flags)

This function initializes the subsystems specified by flags

Definition at line 253 of file SDL.c.

254 {
255  return SDL_InitSubSystem(flags);
256 }

References SDL_InitSubSystem().

◆ SDL_InitSubSystem()

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 106 of file SDL.c.

107 {
108  if (!SDL_MainIsReady) {
109  SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
110  return -1;
111  }
112 
113  /* Clear the error message */
114  SDL_ClearError();
115 
116  if ((flags & SDL_INIT_GAMECONTROLLER)) {
117  /* game controller implies joystick */
119  }
120 
122  /* video or joystick implies events */
124  }
125 
126 #if SDL_VIDEO_DRIVER_WINDOWS
128  if (SDL_HelperWindowCreate() < 0) {
129  return -1;
130  }
131  }
132 #endif
133 
134 #if !SDL_TIMERS_DISABLED
135  SDL_TicksInit();
136 #endif
137 
138  /* Initialize the event subsystem */
139  if ((flags & SDL_INIT_EVENTS)) {
140 #if !SDL_EVENTS_DISABLED
142  if (SDL_EventsInit() < 0) {
143  return (-1);
144  }
145  }
147 #else
148  return SDL_SetError("SDL not built with events support");
149 #endif
150  }
151 
152  /* Initialize the timer subsystem */
153  if ((flags & SDL_INIT_TIMER)){
154 #if !SDL_TIMERS_DISABLED
156  if (SDL_TimerInit() < 0) {
157  return (-1);
158  }
159  }
161 #else
162  return SDL_SetError("SDL not built with timer support");
163 #endif
164  }
165 
166  /* Initialize the video subsystem */
167  if ((flags & SDL_INIT_VIDEO)){
168 #if !SDL_VIDEO_DISABLED
170  if (SDL_VideoInit(NULL) < 0) {
171  return (-1);
172  }
173  }
175 #else
176  return SDL_SetError("SDL not built with video support");
177 #endif
178  }
179 
180  /* Initialize the audio subsystem */
181  if ((flags & SDL_INIT_AUDIO)){
182 #if !SDL_AUDIO_DISABLED
184  if (SDL_AudioInit(NULL) < 0) {
185  return (-1);
186  }
187  }
189 #else
190  return SDL_SetError("SDL not built with audio support");
191 #endif
192  }
193 
194  /* Initialize the joystick subsystem */
195  if ((flags & SDL_INIT_JOYSTICK)){
196 #if !SDL_JOYSTICK_DISABLED
198  if (SDL_JoystickInit() < 0) {
199  return (-1);
200  }
201  }
203 #else
204  return SDL_SetError("SDL not built with joystick support");
205 #endif
206  }
207 
209 #if !SDL_JOYSTICK_DISABLED
211  if (SDL_GameControllerInit() < 0) {
212  return (-1);
213  }
214  }
216 #else
217  return SDL_SetError("SDL not built with joystick support");
218 #endif
219  }
220 
221  /* Initialize the haptic subsystem */
222  if ((flags & SDL_INIT_HAPTIC)){
223 #if !SDL_HAPTIC_DISABLED
225  if (SDL_HapticInit() < 0) {
226  return (-1);
227  }
228  }
230 #else
231  return SDL_SetError("SDL not built with haptic (force feedback) support");
232 #endif
233  }
234 
235  /* Initialize the sensor subsystem */
236  if ((flags & SDL_INIT_SENSOR)){
237 #if !SDL_SENSOR_DISABLED
239  if (SDL_SensorInit() < 0) {
240  return (-1);
241  }
242  }
244 #else
245  return SDL_SetError("SDL not built with sensor support");
246 #endif
247  }
248 
249  return (0);
250 }

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

Referenced by SDL_Init().

◆ SDL_Quit()

void SDL_Quit ( void  )

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

Definition at line 89 of file SDL_dynapi_procs.h.

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_QuitSubSystem()

void SDL_QuitSubSystem ( Uint32  flags)

This function cleans up specific SDL subsystems

Definition at line 259 of file SDL.c.

260 {
261  /* Shut down requested initialized subsystems */
262 #if !SDL_SENSOR_DISABLED
263  if ((flags & SDL_INIT_SENSOR)) {
265  SDL_SensorQuit();
266  }
268  }
269 #endif
270 
271 #if !SDL_JOYSTICK_DISABLED
272  if ((flags & SDL_INIT_GAMECONTROLLER)) {
273  /* game controller implies joystick */
275 
278  }
280  }
281 
282  if ((flags & SDL_INIT_JOYSTICK)) {
283  /* joystick implies events */
285 
288  }
290  }
291 #endif
292 
293 #if !SDL_HAPTIC_DISABLED
294  if ((flags & SDL_INIT_HAPTIC)) {
296  SDL_HapticQuit();
297  }
299  }
300 #endif
301 
302 #if !SDL_AUDIO_DISABLED
303  if ((flags & SDL_INIT_AUDIO)) {
305  SDL_AudioQuit();
306  }
308  }
309 #endif
310 
311 #if !SDL_VIDEO_DISABLED
312  if ((flags & SDL_INIT_VIDEO)) {
313  /* video implies events */
315 
317  SDL_VideoQuit();
318  }
320  }
321 #endif
322 
323 #if !SDL_TIMERS_DISABLED
324  if ((flags & SDL_INIT_TIMER)) {
326  SDL_TimerQuit();
327  }
329  }
330 #endif
331 
332 #if !SDL_EVENTS_DISABLED
333  if ((flags & SDL_INIT_EVENTS)) {
335  SDL_EventsQuit();
336  }
338  }
339 #endif
340 }

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

Referenced by SDL_Quit().

◆ SDL_WasInit()

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 343 of file SDL.c.

344 {
345  int i;
346  int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
347  Uint32 initialized = 0;
348 
349  /* Fast path for checking one flag */
351  int subsystem_index = SDL_MostSignificantBitIndex32(flags);
352  return SDL_SubsystemRefCount[subsystem_index] ? flags : 0;
353  }
354 
355  if (!flags) {
357  }
358 
359  num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
360 
361  /* Iterate over each bit in flags, and check the matching subsystem. */
362  for (i = 0; i < num_subsystems; ++i) {
363  if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
364  initialized |= (1 << i);
365  }
366 
367  flags >>= 1;
368  }
369 
370  return initialized;
371 }

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

Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_AudioInit
#define SDL_AudioInit
Definition: SDL_dynapi_overrides.h:75
SDL_PrivateShouldInitSubsystem
static SDL_bool SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
Definition: SDL.c:78
SDL_TimerQuit
void SDL_TimerQuit(void)
Definition: SDL_timer.c:239
SDL_ClearError
#define SDL_ClearError
Definition: SDL_dynapi_overrides.h:114
SDL_HapticQuit
void SDL_HapticQuit(void)
Definition: SDL_haptic.c:394
SDL_PrivateSubsystemRefCountIncr
static void SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
Definition: SDL.c:59
NULL
#define NULL
Definition: begin_code.h:167
SDL_JoystickInit
int SDL_JoystickInit(void)
Definition: SDL_joystick.c:114
SDL_SubsystemRefCount
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:55
SDL_INIT_JOYSTICK
#define SDL_INIT_JOYSTICK
Definition: SDL.h:80
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:83
SDL_TimerInit
int SDL_TimerInit(void)
Definition: SDL_timer.c:207
SDL_TicksInit
void SDL_TicksInit(void)
SDL_SensorInit
int SDL_SensorInit(void)
Definition: SDL_sensor.c:69
SDL_AudioQuit
#define SDL_AudioQuit
Definition: SDL_dynapi_overrides.h:76
SDL_GameControllerInit
int SDL_GameControllerInit(void)
Definition: SDL_gamecontroller.c:1374
SDL_SensorQuit
void SDL_SensorQuit(void)
Definition: SDL_sensor.c:440
SDL_INIT_SENSOR
#define SDL_INIT_SENSOR
Definition: SDL.h:84
SDL_PrivateSubsystemRefCountDecr
static void SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
Definition: SDL.c:68
SDL_HapticInit
int SDL_HapticInit(void)
Definition: SDL_haptic.c:39
SDL_HasExactlyOneBitSet32
SDL_FORCE_INLINE SDL_bool SDL_HasExactlyOneBitSet32(Uint32 x)
Definition: SDL_bits.h:105
SDL_JoystickQuit
void SDL_JoystickQuit(void)
Definition: SDL_joystick.c:697
SDL_VideoInit
#define SDL_VideoInit
Definition: SDL_dynapi_overrides.h:498
SDL_min
#define SDL_min(x, y)
Definition: SDL_stdinc.h:406
SDL_PrivateShouldQuitSubsystem
static SDL_bool SDL_PrivateShouldQuitSubsystem(Uint32 subsystem)
Definition: SDL.c:87
SDL_INIT_HAPTIC
#define SDL_INIT_HAPTIC
Definition: SDL.h:81
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:79
SDL_INIT_TIMER
#define SDL_INIT_TIMER
Definition: SDL.h:77
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_InitSubSystem
int SDL_InitSubSystem(Uint32 flags)
Definition: SDL.c:106
SDL_GameControllerQuit
void SDL_GameControllerQuit(void)
Definition: SDL_gamecontroller.c:1931
SDL_VideoQuit
#define SDL_VideoQuit
Definition: SDL_dynapi_overrides.h:499
SDL_MostSignificantBitIndex32
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
Definition: SDL_bits.h:61
SDL_INIT_GAMECONTROLLER
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:82
SDL_EventsInit
int SDL_EventsInit(void)
Definition: SDL_events.c:1002
SDL_EventsQuit
void SDL_EventsQuit(void)
Definition: SDL_events.c:1016
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
SDL_INIT_EVERYTHING
#define SDL_INIT_EVERYTHING
Definition: SDL.h:86
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:50
SDL_MainIsReady
static SDL_bool SDL_MainIsReady
Definition: SDL.c:52
SDL_INIT_AUDIO
#define SDL_INIT_AUDIO
Definition: SDL.h:78