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.

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   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
 

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_EVENTS   0x00004000u
#define SDL_INIT_EVERYTHING
Value:
( \
)
#define SDL_INIT_SENSOR
Definition: SDL.h:84
#define SDL_INIT_EVENTS
Definition: SDL.h:83
#define SDL_INIT_JOYSTICK
Definition: SDL.h:80
#define SDL_INIT_TIMER
Definition: SDL.h:77
#define SDL_INIT_AUDIO
Definition: SDL.h:78
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:82
#define SDL_INIT_HAPTIC
Definition: SDL.h:81
#define SDL_INIT_VIDEO
Definition: SDL.h:79

Definition at line 86 of file SDL.h.

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

#define SDL_INIT_GAMECONTROLLER   0x00002000u

SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK

Definition at line 82 of file SDL.h.

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

#define SDL_INIT_HAPTIC   0x00001000u
#define SDL_INIT_JOYSTICK   0x00000200u

SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS

Definition at line 80 of file SDL.h.

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

#define SDL_INIT_NOPARACHUTE   0x00100000u

compatibility; this flag is ignored.

Definition at line 85 of file SDL.h.

#define SDL_INIT_SENSOR   0x00008000u

Definition at line 84 of file SDL.h.

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

#define SDL_INIT_TIMER   0x00000001u

Definition at line 77 of file SDL.h.

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

#define SDL_INIT_VIDEO   0x00000020u

SDL_INIT_VIDEO implies SDL_INIT_EVENTS

Definition at line 79 of file SDL.h.

Referenced by main(), SDL_InitSubSystem(), 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 254 of file SDL.c.

References SDL_InitSubSystem().

255 {
256  return SDL_InitSubSystem(flags);
257 }
GLbitfield flags
int SDL_InitSubSystem(Uint32 flags)
Definition: SDL.c:106
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.

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_SENSOR, SDL_INIT_TIMER, SDL_INIT_VIDEO, SDL_JoystickInit(), SDL_MainIsReady, SDL_PrivateShouldInitSubsystem(), SDL_PrivateSubsystemRefCountIncr(), SDL_QuitInit(), SDL_SensorInit(), SDL_SetError, SDL_StartEventLoop(), SDL_TicksInit(), SDL_TimerInit(), and SDL_VideoInit.

Referenced by SDL_Init().

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
141  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
142  if (SDL_StartEventLoop() < 0) {
143  return (-1);
144  }
145  SDL_QuitInit();
146  }
147  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
148 #else
149  return SDL_SetError("SDL not built with events support");
150 #endif
151  }
152 
153  /* Initialize the timer subsystem */
154  if ((flags & SDL_INIT_TIMER)){
155 #if !SDL_TIMERS_DISABLED
156  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
157  if (SDL_TimerInit() < 0) {
158  return (-1);
159  }
160  }
161  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
162 #else
163  return SDL_SetError("SDL not built with timer support");
164 #endif
165  }
166 
167  /* Initialize the video subsystem */
168  if ((flags & SDL_INIT_VIDEO)){
169 #if !SDL_VIDEO_DISABLED
170  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
171  if (SDL_VideoInit(NULL) < 0) {
172  return (-1);
173  }
174  }
175  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
176 #else
177  return SDL_SetError("SDL not built with video support");
178 #endif
179  }
180 
181  /* Initialize the audio subsystem */
182  if ((flags & SDL_INIT_AUDIO)){
183 #if !SDL_AUDIO_DISABLED
184  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
185  if (SDL_AudioInit(NULL) < 0) {
186  return (-1);
187  }
188  }
189  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
190 #else
191  return SDL_SetError("SDL not built with audio support");
192 #endif
193  }
194 
195  /* Initialize the joystick subsystem */
196  if ((flags & SDL_INIT_JOYSTICK)){
197 #if !SDL_JOYSTICK_DISABLED
198  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
199  if (SDL_JoystickInit() < 0) {
200  return (-1);
201  }
202  }
203  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
204 #else
205  return SDL_SetError("SDL not built with joystick support");
206 #endif
207  }
208 
209  if ((flags & SDL_INIT_GAMECONTROLLER)){
210 #if !SDL_JOYSTICK_DISABLED
211  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
212  if (SDL_GameControllerInit() < 0) {
213  return (-1);
214  }
215  }
216  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
217 #else
218  return SDL_SetError("SDL not built with joystick support");
219 #endif
220  }
221 
222  /* Initialize the haptic subsystem */
223  if ((flags & SDL_INIT_HAPTIC)){
224 #if !SDL_HAPTIC_DISABLED
225  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
226  if (SDL_HapticInit() < 0) {
227  return (-1);
228  }
229  }
230  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
231 #else
232  return SDL_SetError("SDL not built with haptic (force feedback) support");
233 #endif
234  }
235 
236  /* Initialize the sensor subsystem */
237  if ((flags & SDL_INIT_SENSOR)){
238 #if !SDL_SENSOR_DISABLED
239  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
240  if (SDL_SensorInit() < 0) {
241  return (-1);
242  }
243  }
244  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_SENSOR);
245 #else
246  return SDL_SetError("SDL not built with sensor support");
247 #endif
248  }
249 
250  return (0);
251 }
#define SDL_INIT_SENSOR
Definition: SDL.h:84
#define SDL_ClearError
#define SDL_INIT_EVENTS
Definition: SDL.h:83
static SDL_bool SDL_MainIsReady
Definition: SDL.c:52
#define SDL_INIT_JOYSTICK
Definition: SDL.h:80
#define SDL_AudioInit
int SDL_JoystickInit(void)
Definition: SDL_joystick.c:114
int SDL_StartEventLoop(void)
Definition: SDL_events.c:391
int SDL_TimerInit(void)
Definition: SDL_timer.c:207
int SDL_QuitInit(void)
Definition: SDL_quit.c:92
static void SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
Definition: SDL.c:59
#define SDL_VideoInit
int SDL_SensorInit(void)
Definition: SDL_sensor.c:69
#define NULL
Definition: begin_code.h:164
static SDL_bool SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
Definition: SDL.c:78
#define SDL_SetError
GLbitfield flags
#define SDL_INIT_TIMER
Definition: SDL.h:77
#define SDL_INIT_AUDIO
Definition: SDL.h:78
void SDL_TicksInit(void)
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:82
#define SDL_INIT_HAPTIC
Definition: SDL.h:81
int SDL_GameControllerInit(void)
int SDL_HapticInit(void)
Definition: SDL_haptic.c:35
#define SDL_INIT_VIDEO
Definition: SDL.h:79
void SDL_Quit ( void  )

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

Definition at line 370 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.

371 {
373 
374  /* Quit all subsystems */
375 #if SDL_VIDEO_DRIVER_WINDOWS
376  SDL_HelperWindowDestroy();
377 #endif
379 
380 #if !SDL_TIMERS_DISABLED
381  SDL_TicksQuit();
382 #endif
383 
384  SDL_ClearHints();
387 
388  /* Now that every subsystem has been quit, we reset the subsystem refcount
389  * and the list of initialized subsystems.
390  */
392 
394 }
#define SDL_LogResetPriorities
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:55
void SDL_QuitSubSystem(Uint32 flags)
Definition: SDL.c:260
#define SDL_ClearHints
static SDL_bool SDL_bInMainQuit
Definition: SDL.c:54
void SDL_AssertionsQuit(void)
Definition: SDL_assert.c:397
#define SDL_INIT_EVERYTHING
Definition: SDL.h:86
GLuint GLfloat x0
void SDL_TicksQuit(void)
#define SDL_memset
void SDL_QuitSubSystem ( Uint32  flags)

This function cleans up specific SDL subsystems

Definition at line 260 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_SENSOR, SDL_INIT_TIMER, SDL_INIT_VIDEO, SDL_JoystickQuit(), SDL_PrivateShouldQuitSubsystem(), SDL_PrivateSubsystemRefCountDecr(), SDL_QuitQuit(), SDL_SensorQuit(), SDL_StopEventLoop(), SDL_TimerQuit(), and SDL_VideoQuit.

Referenced by SDL_Quit().

261 {
262  /* Shut down requested initialized subsystems */
263 #if !SDL_SENSOR_DISABLED
264  if ((flags & SDL_INIT_SENSOR)) {
265  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_SENSOR)) {
266  SDL_SensorQuit();
267  }
268  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_SENSOR);
269  }
270 #endif
271 
272 #if !SDL_JOYSTICK_DISABLED
273  if ((flags & SDL_INIT_GAMECONTROLLER)) {
274  /* game controller implies joystick */
276 
277  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
279  }
280  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
281  }
282 
283  if ((flags & SDL_INIT_JOYSTICK)) {
284  /* joystick implies events */
286 
287  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
289  }
290  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_JOYSTICK);
291  }
292 #endif
293 
294 #if !SDL_HAPTIC_DISABLED
295  if ((flags & SDL_INIT_HAPTIC)) {
296  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
297  SDL_HapticQuit();
298  }
299  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_HAPTIC);
300  }
301 #endif
302 
303 #if !SDL_AUDIO_DISABLED
304  if ((flags & SDL_INIT_AUDIO)) {
305  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
306  SDL_AudioQuit();
307  }
308  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_AUDIO);
309  }
310 #endif
311 
312 #if !SDL_VIDEO_DISABLED
313  if ((flags & SDL_INIT_VIDEO)) {
314  /* video implies events */
316 
317  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
318  SDL_VideoQuit();
319  }
320  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_VIDEO);
321  }
322 #endif
323 
324 #if !SDL_TIMERS_DISABLED
325  if ((flags & SDL_INIT_TIMER)) {
326  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
327  SDL_TimerQuit();
328  }
329  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
330  }
331 #endif
332 
333 #if !SDL_EVENTS_DISABLED
334  if ((flags & SDL_INIT_EVENTS)) {
335  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
336  SDL_QuitQuit();
338  }
339  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
340  }
341 #endif
342 }
#define SDL_INIT_SENSOR
Definition: SDL.h:84
#define SDL_INIT_EVENTS
Definition: SDL.h:83
void SDL_TimerQuit(void)
Definition: SDL_timer.c:239
void SDL_HapticQuit(void)
Definition: SDL_haptic.c:390
#define SDL_INIT_JOYSTICK
Definition: SDL.h:80
#define SDL_AudioQuit
void SDL_GameControllerQuit(void)
GLbitfield flags
#define SDL_INIT_TIMER
Definition: SDL.h:77
#define SDL_INIT_AUDIO
Definition: SDL.h:78
static void SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
Definition: SDL.c:68
#define SDL_VideoQuit
void SDL_SensorQuit(void)
Definition: SDL_sensor.c:440
static SDL_bool SDL_PrivateShouldQuitSubsystem(Uint32 subsystem)
Definition: SDL.c:87
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:82
void SDL_JoystickQuit(void)
Definition: SDL_joystick.c:697
#define SDL_INIT_HAPTIC
Definition: SDL.h:81
#define SDL_INIT_VIDEO
Definition: SDL.h:79
void SDL_QuitQuit(void)
Definition: SDL_quit.c:128
void SDL_StopEventLoop(void)
Definition: SDL_events.c:317
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 345 of file SDL.c.

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

346 {
347  int i;
348  int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
349  Uint32 initialized = 0;
350 
351  if (!flags) {
353  }
354 
355  num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
356 
357  /* Iterate over each bit in flags, and check the matching subsystem. */
358  for (i = 0; i < num_subsystems; ++i) {
359  if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
360  initialized |= (1 << i);
361  }
362 
363  flags >>= 1;
364  }
365 
366  return initialized;
367 }
#define SDL_min(x, y)
Definition: SDL_stdinc.h:406
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:55
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
Definition: SDL_bits.h:61
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
#define SDL_INIT_EVERYTHING
Definition: SDL.h:86
GLbitfield flags
uint32_t Uint32
Definition: SDL_stdinc.h:203
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115