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_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_EVENTS   0x00004000
#define SDL_INIT_EVERYTHING
Value:
( \
)
#define SDL_INIT_EVENTS
Definition: SDL.h:81
#define SDL_INIT_JOYSTICK
Definition: SDL.h:78
#define SDL_INIT_TIMER
Definition: SDL.h:75
#define SDL_INIT_AUDIO
Definition: SDL.h:76
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:80
#define SDL_INIT_HAPTIC
Definition: SDL.h:79
#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
#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

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

243 {
244  return SDL_InitSubSystem(flags);
245 }
GLbitfield flags
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().

109 {
110  if (!SDL_MainIsReady) {
111  SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
112  return -1;
113  }
114 
115  /* Clear the error message */
116  SDL_ClearError();
117 
118 #if SDL_VIDEO_DRIVER_WINDOWS
120  if (SDL_HelperWindowCreate() < 0) {
121  return -1;
122  }
123  }
124 #endif
125 
126 #if !SDL_TIMERS_DISABLED
127  SDL_TicksInit();
128 #endif
129 
130  if ((flags & SDL_INIT_GAMECONTROLLER)) {
131  /* game controller implies joystick */
133  }
134 
136  /* video or joystick implies events */
138  }
139 
140  /* Initialize the event subsystem */
141  if ((flags & SDL_INIT_EVENTS)) {
142 #if !SDL_EVENTS_DISABLED
143  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
144  if (SDL_StartEventLoop() < 0) {
145  return (-1);
146  }
147  SDL_QuitInit();
148  }
149  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
150 #else
151  return SDL_SetError("SDL not built with events support");
152 #endif
153  }
154 
155  /* Initialize the timer subsystem */
156  if ((flags & SDL_INIT_TIMER)){
157 #if !SDL_TIMERS_DISABLED
158  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
159  if (SDL_TimerInit() < 0) {
160  return (-1);
161  }
162  }
163  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
164 #else
165  return SDL_SetError("SDL not built with timer support");
166 #endif
167  }
168 
169  /* Initialize the video subsystem */
170  if ((flags & SDL_INIT_VIDEO)){
171 #if !SDL_VIDEO_DISABLED
172  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
173  if (SDL_VideoInit(NULL) < 0) {
174  return (-1);
175  }
176  }
177  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
178 #else
179  return SDL_SetError("SDL not built with video support");
180 #endif
181  }
182 
183  /* Initialize the audio subsystem */
184  if ((flags & SDL_INIT_AUDIO)){
185 #if !SDL_AUDIO_DISABLED
186  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
187  if (SDL_AudioInit(NULL) < 0) {
188  return (-1);
189  }
190  }
191  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
192 #else
193  return SDL_SetError("SDL not built with audio support");
194 #endif
195  }
196 
197  /* Initialize the joystick subsystem */
198  if ((flags & SDL_INIT_JOYSTICK)){
199 #if !SDL_JOYSTICK_DISABLED
200  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
201  if (SDL_JoystickInit() < 0) {
202  return (-1);
203  }
204  }
205  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
206 #else
207  return SDL_SetError("SDL not built with joystick support");
208 #endif
209  }
210 
211  if ((flags & SDL_INIT_GAMECONTROLLER)){
212 #if !SDL_JOYSTICK_DISABLED
213  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
214  if (SDL_GameControllerInit() < 0) {
215  return (-1);
216  }
217  }
218  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
219 #else
220  return SDL_SetError("SDL not built with joystick support");
221 #endif
222  }
223 
224  /* Initialize the haptic subsystem */
225  if ((flags & SDL_INIT_HAPTIC)){
226 #if !SDL_HAPTIC_DISABLED
227  if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
228  if (SDL_HapticInit() < 0) {
229  return (-1);
230  }
231  }
232  SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
233 #else
234  return SDL_SetError("SDL not built with haptic (force feedback) support");
235 #endif
236  }
237 
238  return (0);
239 }
#define SDL_ClearError
#define SDL_INIT_EVENTS
Definition: SDL.h:81
static SDL_bool SDL_MainIsReady
Definition: SDL.c:54
#define SDL_INIT_JOYSTICK
Definition: SDL.h:78
#define SDL_AudioInit
int SDL_JoystickInit(void)
Definition: SDL_joystick.c:50
int SDL_StartEventLoop(void)
Definition: SDL_events.c:160
int SDL_QuitInit(void)
Definition: SDL_quit.c:92
static void SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
Definition: SDL.c:61
#define SDL_VideoInit
#define NULL
Definition: begin_code.h:143
static SDL_bool SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
Definition: SDL.c:80
#define SDL_SetError
#define SDL_INIT_TIMER
Definition: SDL.h:75
#define SDL_INIT_AUDIO
Definition: SDL.h:76
void SDL_TicksInit(void)
GLbitfield flags
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:80
#define SDL_INIT_HAPTIC
Definition: SDL.h:79
int SDL_GameControllerInit(void)
int SDL_HapticInit(void)
Definition: SDL_haptic.c:35
#define SDL_INIT_VIDEO
Definition: SDL.h:77
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.

350 {
352 
353  /* Quit all subsystems */
354 #if SDL_VIDEO_DRIVER_WINDOWS
355  SDL_HelperWindowDestroy();
356 #endif
358 
359 #if !SDL_TIMERS_DISABLED
360  SDL_TicksQuit();
361 #endif
362 
363  SDL_ClearHints();
366 
367  /* Now that every subsystem has been quit, we reset the subsystem refcount
368  * and the list of initialized subsystems.
369  */
371 
373 }
#define SDL_LogResetPriorities
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:57
void SDL_QuitSubSystem(Uint32 flags)
Definition: SDL.c:248
#define SDL_ClearHints
static SDL_bool SDL_bInMainQuit
Definition: SDL.c:56
void SDL_TicksQuit(void)
void SDL_AssertionsQuit(void)
Definition: SDL_assert.c:332
#define SDL_INIT_EVERYTHING
Definition: SDL.h:83
GLuint GLfloat x0
#define SDL_memset
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().

249 {
250  /* Shut down requested initialized subsystems */
251 #if !SDL_JOYSTICK_DISABLED
252  if ((flags & SDL_INIT_GAMECONTROLLER)) {
253  /* game controller implies joystick */
255 
256  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
258  }
259  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
260  }
261 
262  if ((flags & SDL_INIT_JOYSTICK)) {
263  /* joystick implies events */
265 
266  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
268  }
269  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_JOYSTICK);
270  }
271 #endif
272 
273 #if !SDL_HAPTIC_DISABLED
274  if ((flags & SDL_INIT_HAPTIC)) {
275  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
276  SDL_HapticQuit();
277  }
278  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_HAPTIC);
279  }
280 #endif
281 
282 #if !SDL_AUDIO_DISABLED
283  if ((flags & SDL_INIT_AUDIO)) {
284  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
285  SDL_AudioQuit();
286  }
287  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_AUDIO);
288  }
289 #endif
290 
291 #if !SDL_VIDEO_DISABLED
292  if ((flags & SDL_INIT_VIDEO)) {
293  /* video implies events */
295 
296  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
297  SDL_VideoQuit();
298  }
299  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_VIDEO);
300  }
301 #endif
302 
303 #if !SDL_TIMERS_DISABLED
304  if ((flags & SDL_INIT_TIMER)) {
305  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
306  SDL_TimerQuit();
307  }
308  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
309  }
310 #endif
311 
312 #if !SDL_EVENTS_DISABLED
313  if ((flags & SDL_INIT_EVENTS)) {
314  if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
315  SDL_QuitQuit();
317  }
318  SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
319  }
320 #endif
321 }
#define SDL_INIT_EVENTS
Definition: SDL.h:81
void SDL_HapticQuit(void)
Definition: SDL_haptic.c:389
#define SDL_INIT_JOYSTICK
Definition: SDL.h:78
void SDL_TimerQuit(void)
Definition: SDL_timer.c:246
#define SDL_AudioQuit
void SDL_GameControllerQuit(void)
#define SDL_INIT_TIMER
Definition: SDL.h:75
#define SDL_INIT_AUDIO
Definition: SDL.h:76
static void SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
Definition: SDL.c:70
#define SDL_VideoQuit
static SDL_bool SDL_PrivateShouldQuitSubsystem(Uint32 subsystem)
Definition: SDL.c:89
GLbitfield flags
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:80
void SDL_JoystickQuit(void)
Definition: SDL_joystick.c:458
#define SDL_INIT_HAPTIC
Definition: SDL.h:79
#define SDL_INIT_VIDEO
Definition: SDL.h:77
void SDL_QuitQuit(void)
Definition: SDL_quit.c:130
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.

325 {
326  int i;
327  int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
328  Uint32 initialized = 0;
329 
330  if (!flags) {
332  }
333 
334  num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
335 
336  /* Iterate over each bit in flags, and check the matching subsystem. */
337  for (i = 0; i < num_subsystems; ++i) {
338  if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
339  initialized |= (1 << i);
340  }
341 
342  flags >>= 1;
343  }
344 
345  return initialized;
346 }
#define SDL_min(x, y)
Definition: SDL_stdinc.h:345
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:57
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
Definition: SDL_bits.h:51
#define SDL_INIT_EVERYTHING
Definition: SDL.h:83
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
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93
GLbitfield flags