SDL_init.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryInit
  20. *
  21. * SDL subsystem init and quit functions.
  22. */
  23. #ifndef SDL_init_h_
  24. #define SDL_init_h_
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_begin_code.h>
  28. /* Set up for C function definitions, even when using C++ */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* As of version 0.5, SDL is loaded dynamically into the application */
  33. /**
  34. * Initialization flags for SDL_Init and/or SDL_InitSubSystem
  35. *
  36. * These are the flags which may be passed to SDL_Init(). You should specify
  37. * the subsystems which you will be using in your application.
  38. *
  39. * \since This datatype is available since SDL 3.0.0.
  40. *
  41. * \sa SDL_Init
  42. * \sa SDL_Quit
  43. * \sa SDL_InitSubSystem
  44. * \sa SDL_QuitSubSystem
  45. * \sa SDL_WasInit
  46. */
  47. typedef Uint32 SDL_InitFlags;
  48. #define SDL_INIT_TIMER 0x00000001u
  49. #define SDL_INIT_AUDIO 0x00000010u /**< `SDL_INIT_AUDIO` implies `SDL_INIT_EVENTS` */
  50. #define SDL_INIT_VIDEO 0x00000020u /**< `SDL_INIT_VIDEO` implies `SDL_INIT_EVENTS` */
  51. #define SDL_INIT_JOYSTICK 0x00000200u /**< `SDL_INIT_JOYSTICK` implies `SDL_INIT_EVENTS`, should be initialized on the same thread as SDL_INIT_VIDEO on Windows if you don't set SDL_HINT_JOYSTICK_THREAD */
  52. #define SDL_INIT_HAPTIC 0x00001000u
  53. #define SDL_INIT_GAMEPAD 0x00002000u /**< `SDL_INIT_GAMEPAD` implies `SDL_INIT_JOYSTICK` */
  54. #define SDL_INIT_EVENTS 0x00004000u
  55. #define SDL_INIT_SENSOR 0x00008000u /**< `SDL_INIT_SENSOR` implies `SDL_INIT_EVENTS` */
  56. #define SDL_INIT_CAMERA 0x00010000u /**< `SDL_INIT_CAMERA` implies `SDL_INIT_EVENTS` */
  57. /**
  58. * Initialize the SDL library.
  59. *
  60. * SDL_Init() simply forwards to calling SDL_InitSubSystem(). Therefore, the
  61. * two may be used interchangeably. Though for readability of your code
  62. * SDL_InitSubSystem() might be preferred.
  63. *
  64. * The file I/O (for example: SDL_IOFromFile) and threading (SDL_CreateThread)
  65. * subsystems are initialized by default. Message boxes
  66. * (SDL_ShowSimpleMessageBox) also attempt to work without initializing the
  67. * video subsystem, in hopes of being useful in showing an error dialog when
  68. * SDL_Init fails. You must specifically initialize other subsystems if you
  69. * use them in your application.
  70. *
  71. * Logging (such as SDL_Log) works without initialization, too.
  72. *
  73. * `flags` may be any of the following OR'd together:
  74. *
  75. * - `SDL_INIT_TIMER`: timer subsystem
  76. * - `SDL_INIT_AUDIO`: audio subsystem; automatically initializes the events
  77. * subsystem
  78. * - `SDL_INIT_VIDEO`: video subsystem; automatically initializes the events
  79. * subsystem
  80. * - `SDL_INIT_JOYSTICK`: joystick subsystem; automatically initializes the
  81. * events subsystem
  82. * - `SDL_INIT_HAPTIC`: haptic (force feedback) subsystem
  83. * - `SDL_INIT_GAMEPAD`: gamepad subsystem; automatically initializes the
  84. * joystick subsystem
  85. * - `SDL_INIT_EVENTS`: events subsystem
  86. * - `SDL_INIT_SENSOR`: sensor subsystem; automatically initializes the events
  87. * subsystem
  88. * - `SDL_INIT_CAMERA`: camera subsystem; automatically initializes the events
  89. * subsystem
  90. *
  91. * Subsystem initialization is ref-counted, you must call SDL_QuitSubSystem()
  92. * for each SDL_InitSubSystem() to correctly shutdown a subsystem manually (or
  93. * call SDL_Quit() to force shutdown). If a subsystem is already loaded then
  94. * this call will increase the ref-count and return.
  95. *
  96. * \param flags subsystem initialization flags
  97. * \returns 0 on success or a negative error code on failure; call
  98. * SDL_GetError() for more information.
  99. *
  100. * \since This function is available since SDL 3.0.0.
  101. *
  102. * \sa SDL_InitSubSystem
  103. * \sa SDL_Quit
  104. * \sa SDL_SetMainReady
  105. * \sa SDL_WasInit
  106. */
  107. extern DECLSPEC int SDLCALL SDL_Init(SDL_InitFlags flags);
  108. /**
  109. * Compatibility function to initialize the SDL library.
  110. *
  111. * This function and SDL_Init() are interchangeable.
  112. *
  113. * \param flags any of the flags used by SDL_Init(); see SDL_Init for details.
  114. * \returns 0 on success or a negative error code on failure; call
  115. * SDL_GetError() for more information.
  116. *
  117. * \since This function is available since SDL 3.0.0.
  118. *
  119. * \sa SDL_Init
  120. * \sa SDL_Quit
  121. * \sa SDL_QuitSubSystem
  122. */
  123. extern DECLSPEC int SDLCALL SDL_InitSubSystem(SDL_InitFlags flags);
  124. /**
  125. * Shut down specific SDL subsystems.
  126. *
  127. * You still need to call SDL_Quit() even if you close all open subsystems
  128. * with SDL_QuitSubSystem().
  129. *
  130. * \param flags any of the flags used by SDL_Init(); see SDL_Init for details.
  131. *
  132. * \since This function is available since SDL 3.0.0.
  133. *
  134. * \sa SDL_InitSubSystem
  135. * \sa SDL_Quit
  136. */
  137. extern DECLSPEC void SDLCALL SDL_QuitSubSystem(SDL_InitFlags flags);
  138. /**
  139. * Get a mask of the specified subsystems which are currently initialized.
  140. *
  141. * \param flags any of the flags used by SDL_Init(); see SDL_Init for details.
  142. * \returns a mask of all initialized subsystems if `flags` is 0, otherwise it
  143. * returns the initialization status of the specified subsystems.
  144. *
  145. * \since This function is available since SDL 3.0.0.
  146. *
  147. * \sa SDL_Init
  148. * \sa SDL_InitSubSystem
  149. */
  150. extern DECLSPEC SDL_InitFlags SDLCALL SDL_WasInit(SDL_InitFlags flags);
  151. /**
  152. * Clean up all initialized subsystems.
  153. *
  154. * You should call this function even if you have already shutdown each
  155. * initialized subsystem with SDL_QuitSubSystem(). It is safe to call this
  156. * function even in the case of errors in initialization.
  157. *
  158. * You can use this function with atexit() to ensure that it is run when your
  159. * application is shutdown, but it is not wise to do this from a library or
  160. * other dynamically loaded code.
  161. *
  162. * \since This function is available since SDL 3.0.0.
  163. *
  164. * \sa SDL_Init
  165. * \sa SDL_QuitSubSystem
  166. */
  167. extern DECLSPEC void SDLCALL SDL_Quit(void);
  168. /* Ends C function definitions when using C++ */
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #include <SDL3/SDL_close_code.h>
  173. #endif /* SDL_init_h_ */