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_metal.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 "SDL_locale.h"
#include "SDL_misc.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 81 of file SDL.h.

◆ SDL_INIT_EVENTS

#define SDL_INIT_EVENTS   0x00004000u

Definition at line 86 of file SDL.h.

◆ SDL_INIT_EVERYTHING

#define SDL_INIT_EVERYTHING
Value:
( \
)
#define SDL_INIT_SENSOR
Definition: SDL.h:87
#define SDL_INIT_AUDIO
Definition: SDL.h:81
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:85
#define SDL_INIT_EVENTS
Definition: SDL.h:86
#define SDL_INIT_HAPTIC
Definition: SDL.h:84
#define SDL_INIT_VIDEO
Definition: SDL.h:82

Definition at line 89 of file SDL.h.

◆ SDL_INIT_GAMECONTROLLER

#define SDL_INIT_GAMECONTROLLER   0x00002000u

SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK

Definition at line 85 of file SDL.h.

◆ SDL_INIT_HAPTIC

#define SDL_INIT_HAPTIC   0x00001000u

Definition at line 84 of file SDL.h.

◆ SDL_INIT_JOYSTICK

#define SDL_INIT_JOYSTICK   0x00000200u

SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS

Definition at line 83 of file SDL.h.

◆ SDL_INIT_NOPARACHUTE

#define SDL_INIT_NOPARACHUTE   0x00100000u

compatibility; this flag is ignored.

Definition at line 88 of file SDL.h.

◆ SDL_INIT_SENSOR

#define SDL_INIT_SENSOR   0x00008000u

Definition at line 87 of file SDL.h.

◆ SDL_INIT_TIMER

#define SDL_INIT_TIMER   0x00000001u

Definition at line 80 of file SDL.h.

◆ SDL_INIT_VIDEO

#define SDL_INIT_VIDEO   0x00000020u

SDL_INIT_VIDEO implies SDL_INIT_EVENTS

Definition at line 82 of file SDL.h.

Function Documentation

◆ SDL_Init()

int SDL_Init ( Uint32  flags)

This function initializes the subsystems specified by flags

Definition at line 299 of file SDL.c.

300 {
301  return SDL_InitSubSystem(flags);
302 }
int SDL_InitSubSystem(Uint32 flags)
Definition: SDL.c:148
GLbitfield flags

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

149 {
150  if (!SDL_MainIsReady) {
151  SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
152  return -1;
153  }
154 
155  /* Clear the error message */
156  SDL_ClearError();
157 
158  if ((flags & SDL_INIT_GAMECONTROLLER)) {
159  /* game controller implies joystick */
161  }
162 
164  /* video or joystick implies events */
166  }
167 
168 #if SDL_THREAD_OS2
169  SDL_OS2TLSAlloc(); /* thread/os2/SDL_systls.c */
170 #endif
171 
172 #if SDL_VIDEO_DRIVER_WINDOWS
174  if (SDL_HelperWindowCreate() < 0) {
175  return -1;
176  }
177  }
178 #endif
179 
180 #if !SDL_TIMERS_DISABLED
181  SDL_TicksInit();
182 #endif
183 
184  /* Initialize the event subsystem */
185  if ((flags & SDL_INIT_EVENTS)) {
186 #if !SDL_EVENTS_DISABLED
188  if (SDL_EventsInit() < 0) {
189  return (-1);
190  }
191  }
193 #else
194  return SDL_SetError("SDL not built with events support");
195 #endif
196  }
197 
198  /* Initialize the timer subsystem */
199  if ((flags & SDL_INIT_TIMER)){
200 #if !SDL_TIMERS_DISABLED
202  if (SDL_TimerInit() < 0) {
203  return (-1);
204  }
205  }
207 #else
208  return SDL_SetError("SDL not built with timer support");
209 #endif
210  }
211 
212  /* Initialize the video subsystem */
213  if ((flags & SDL_INIT_VIDEO)){
214 #if !SDL_VIDEO_DISABLED
216  if (SDL_VideoInit(NULL) < 0) {
217  return (-1);
218  }
219  }
221 #else
222  return SDL_SetError("SDL not built with video support");
223 #endif
224  }
225 
226  /* Initialize the audio subsystem */
227  if ((flags & SDL_INIT_AUDIO)){
228 #if !SDL_AUDIO_DISABLED
230  if (SDL_AudioInit(NULL) < 0) {
231  return (-1);
232  }
233  }
235 #else
236  return SDL_SetError("SDL not built with audio support");
237 #endif
238  }
239 
240  /* Initialize the joystick subsystem */
241  if ((flags & SDL_INIT_JOYSTICK)){
242 #if !SDL_JOYSTICK_DISABLED
244  if (SDL_JoystickInit() < 0) {
245  return (-1);
246  }
247  }
249 #else
250  return SDL_SetError("SDL not built with joystick support");
251 #endif
252  }
253 
255 #if !SDL_JOYSTICK_DISABLED
257  if (SDL_GameControllerInit() < 0) {
258  return (-1);
259  }
260  }
262 #else
263  return SDL_SetError("SDL not built with joystick support");
264 #endif
265  }
266 
267  /* Initialize the haptic subsystem */
268  if ((flags & SDL_INIT_HAPTIC)){
269 #if !SDL_HAPTIC_DISABLED
271  if (SDL_HapticInit() < 0) {
272  return (-1);
273  }
274  }
276 #else
277  return SDL_SetError("SDL not built with haptic (force feedback) support");
278 #endif
279  }
280 
281  /* Initialize the sensor subsystem */
282  if ((flags & SDL_INIT_SENSOR)){
283 #if !SDL_SENSOR_DISABLED
285  if (SDL_SensorInit() < 0) {
286  return (-1);
287  }
288  }
290 #else
291  return SDL_SetError("SDL not built with sensor support");
292 #endif
293  }
294 
295  return (0);
296 }
static void SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
Definition: SDL.c:101
static SDL_bool SDL_MainIsReady
Definition: SDL.c:94
static SDL_bool SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
Definition: SDL.c:120
#define SDL_INIT_TIMER
Definition: SDL.h:80
#define SDL_INIT_JOYSTICK
Definition: SDL.h:83
#define SDL_SetError
#define SDL_AudioInit
#define SDL_VideoInit
#define SDL_ClearError
int SDL_EventsInit(void)
Definition: SDL_events.c:1078
int SDL_GameControllerInit(void)
int SDL_HapticInit(void)
Definition: SDL_haptic.c:38
int SDL_JoystickInit(void)
Definition: SDL_joystick.c:213
int SDL_SensorInit(void)
Definition: SDL_sensor.c:71
int SDL_TimerInit(void)
Definition: SDL_timer.c:207
void SDL_TicksInit(void)
#define NULL
Definition: begin_code.h:163

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

306 {
307 #if SDL_THREAD_OS2
308  SDL_OS2TLSFree(); /* thread/os2/SDL_systls.c */
309 #endif
310 #if defined(__OS2__)
311  SDL_OS2Quit();
312 #endif
313 
314  /* Shut down requested initialized subsystems */
315 #if !SDL_SENSOR_DISABLED
316  if ((flags & SDL_INIT_SENSOR)) {
318  SDL_SensorQuit();
319  }
321  }
322 #endif
323 
324 #if !SDL_JOYSTICK_DISABLED
325  if ((flags & SDL_INIT_GAMECONTROLLER)) {
326  /* game controller implies joystick */
328 
331  }
333  }
334 
335  if ((flags & SDL_INIT_JOYSTICK)) {
336  /* joystick implies events */
338 
341  }
343  }
344 #endif
345 
346 #if !SDL_HAPTIC_DISABLED
347  if ((flags & SDL_INIT_HAPTIC)) {
349  SDL_HapticQuit();
350  }
352  }
353 #endif
354 
355 #if !SDL_AUDIO_DISABLED
356  if ((flags & SDL_INIT_AUDIO)) {
358  SDL_AudioQuit();
359  }
361  }
362 #endif
363 
364 #if !SDL_VIDEO_DISABLED
365  if ((flags & SDL_INIT_VIDEO)) {
366  /* video implies events */
368 
370  SDL_VideoQuit();
371  }
373  }
374 #endif
375 
376 #if !SDL_TIMERS_DISABLED
377  if ((flags & SDL_INIT_TIMER)) {
379  SDL_TimerQuit();
380  }
382  }
383 #endif
384 
385 #if !SDL_EVENTS_DISABLED
386  if ((flags & SDL_INIT_EVENTS)) {
388  SDL_EventsQuit();
389  }
391  }
392 #endif
393 }
static SDL_bool SDL_PrivateShouldQuitSubsystem(Uint32 subsystem)
Definition: SDL.c:129
static void SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
Definition: SDL.c:110
#define SDL_AudioQuit
#define SDL_VideoQuit
void SDL_EventsQuit(void)
Definition: SDL_events.c:1098
void SDL_GameControllerQuit(void)
void SDL_HapticQuit(void)
Definition: SDL_haptic.c:393
void SDL_JoystickQuit(void)
void SDL_OS2Quit(void)
void SDL_SensorQuit(void)
Definition: SDL_sensor.c:442
void SDL_TimerQuit(void)
Definition: SDL_timer.c:239

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_OS2Quit(), 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 396 of file SDL.c.

397 {
398  int i;
399  int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
400  Uint32 initialized = 0;
401 
402  /* Fast path for checking one flag */
404  int subsystem_index = SDL_MostSignificantBitIndex32(flags);
405  return SDL_SubsystemRefCount[subsystem_index] ? flags : 0;
406  }
407 
408  if (!flags) {
410  }
411 
412  num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
413 
414  /* Iterate over each bit in flags, and check the matching subsystem. */
415  for (i = 0; i < num_subsystems; ++i) {
416  if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
417  initialized |= (1 << i);
418  }
419 
420  flags >>= 1;
421  }
422 
423  return initialized;
424 }
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:97
#define SDL_INIT_EVERYTHING
Definition: SDL.h:89
SDL_FORCE_INLINE SDL_bool SDL_HasExactlyOneBitSet32(Uint32 x)
Definition: SDL_bits.h:105
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
Definition: SDL_bits.h:61
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:121
#define SDL_min(x, y)
Definition: SDL_stdinc.h:412
uint32_t Uint32
Definition: SDL_stdinc.h:209
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

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