Atlas - SDL_init.h

Home / ext / SDL / include / SDL3 Lines: 1 | Size: 20850 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22/** 23 * # CategoryInit 24 * 25 * All SDL programs need to initialize the library before starting to work 26 * with it. 27 * 28 * Almost everything can simply call SDL_Init() near startup, with a handful 29 * of flags to specify subsystems to touch. These are here to make sure SDL 30 * does not even attempt to touch low-level pieces of the operating system 31 * that you don't intend to use. For example, you might be using SDL for video 32 * and input but chose an external library for audio, and in this case you 33 * would just need to leave off the `SDL_INIT_AUDIO` flag to make sure that 34 * external library has complete control. 35 * 36 * Most apps, when terminating, should call SDL_Quit(). This will clean up 37 * (nearly) everything that SDL might have allocated, and crucially, it'll 38 * make sure that the display's resolution is back to what the user expects if 39 * you had previously changed it for your game. 40 * 41 * SDL3 apps are strongly encouraged to call SDL_SetAppMetadata() at startup 42 * to fill in details about the program. This is completely optional, but it 43 * helps in small ways (we can provide an About dialog box for the macOS menu, 44 * we can name the app in the system's audio mixer, etc). Those that want to 45 * provide a _lot_ of information should look at the more-detailed 46 * SDL_SetAppMetadataProperty(). 47 */ 48 49#ifndef SDL_init_h_ 50#define SDL_init_h_ 51 52#include <SDL3/SDL_stdinc.h> 53#include <SDL3/SDL_error.h> 54#include <SDL3/SDL_events.h> 55 56#include <SDL3/SDL_begin_code.h> 57/* Set up for C function definitions, even when using C++ */ 58#ifdef __cplusplus 59extern "C" { 60#endif 61 62/* As of version 0.5, SDL is loaded dynamically into the application */ 63 64/** 65 * Initialization flags for SDL_Init and/or SDL_InitSubSystem 66 * 67 * These are the flags which may be passed to SDL_Init(). You should specify 68 * the subsystems which you will be using in your application. 69 * 70 * \since This datatype is available since SDL 3.2.0. 71 * 72 * \sa SDL_Init 73 * \sa SDL_Quit 74 * \sa SDL_InitSubSystem 75 * \sa SDL_QuitSubSystem 76 * \sa SDL_WasInit 77 */ 78typedef Uint32 SDL_InitFlags; 79 80#define SDL_INIT_AUDIO 0x00000010u /**< `SDL_INIT_AUDIO` implies `SDL_INIT_EVENTS` */ 81#define SDL_INIT_VIDEO 0x00000020u /**< `SDL_INIT_VIDEO` implies `SDL_INIT_EVENTS`, should be initialized on the main thread */ 82#define SDL_INIT_JOYSTICK 0x00000200u /**< `SDL_INIT_JOYSTICK` implies `SDL_INIT_EVENTS` */ 83#define SDL_INIT_HAPTIC 0x00001000u 84#define SDL_INIT_GAMEPAD 0x00002000u /**< `SDL_INIT_GAMEPAD` implies `SDL_INIT_JOYSTICK` */ 85#define SDL_INIT_EVENTS 0x00004000u 86#define SDL_INIT_SENSOR 0x00008000u /**< `SDL_INIT_SENSOR` implies `SDL_INIT_EVENTS` */ 87#define SDL_INIT_CAMERA 0x00010000u /**< `SDL_INIT_CAMERA` implies `SDL_INIT_EVENTS` */ 88 89/** 90 * Return values for optional main callbacks. 91 * 92 * Returning SDL_APP_SUCCESS or SDL_APP_FAILURE from SDL_AppInit, 93 * SDL_AppEvent, or SDL_AppIterate will terminate the program and report 94 * success/failure to the operating system. What that means is 95 * platform-dependent. On Unix, for example, on success, the process error 96 * code will be zero, and on failure it will be 1. This interface doesn't 97 * allow you to return specific exit codes, just whether there was an error 98 * generally or not. 99 * 100 * Returning SDL_APP_CONTINUE from these functions will let the app continue 101 * to run. 102 * 103 * See 104 * [Main callbacks in SDL3](https://wiki.libsdl.org/SDL3/README-main-functions#main-callbacks-in-sdl3) 105 * for complete details. 106 * 107 * \since This enum is available since SDL 3.2.0. 108 */ 109typedef enum SDL_AppResult 110{ 111 SDL_APP_CONTINUE, /**< Value that requests that the app continue from the main callbacks. */ 112 SDL_APP_SUCCESS, /**< Value that requests termination with success from the main callbacks. */ 113 SDL_APP_FAILURE /**< Value that requests termination with error from the main callbacks. */ 114} SDL_AppResult; 115 116/** 117 * Function pointer typedef for SDL_AppInit. 118 * 119 * These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind 120 * the scenes for apps using the optional main callbacks. Apps that want to 121 * use this should just implement SDL_AppInit directly. 122 * 123 * \param appstate a place where the app can optionally store a pointer for 124 * future use. 125 * \param argc the standard ANSI C main's argc; number of elements in `argv`. 126 * \param argv the standard ANSI C main's argv; array of command line 127 * arguments. 128 * \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to 129 * terminate with success, SDL_APP_CONTINUE to continue. 130 * 131 * \since This datatype is available since SDL 3.2.0. 132 */ 133typedef SDL_AppResult (SDLCALL *SDL_AppInit_func)(void **appstate, int argc, char *argv[]); 134 135/** 136 * Function pointer typedef for SDL_AppIterate. 137 * 138 * These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind 139 * the scenes for apps using the optional main callbacks. Apps that want to 140 * use this should just implement SDL_AppIterate directly. 141 * 142 * \param appstate an optional pointer, provided by the app in SDL_AppInit. 143 * \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to 144 * terminate with success, SDL_APP_CONTINUE to continue. 145 * 146 * \since This datatype is available since SDL 3.2.0. 147 */ 148typedef SDL_AppResult (SDLCALL *SDL_AppIterate_func)(void *appstate); 149 150/** 151 * Function pointer typedef for SDL_AppEvent. 152 * 153 * These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind 154 * the scenes for apps using the optional main callbacks. Apps that want to 155 * use this should just implement SDL_AppEvent directly. 156 * 157 * \param appstate an optional pointer, provided by the app in SDL_AppInit. 158 * \param event the new event for the app to examine. 159 * \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to 160 * terminate with success, SDL_APP_CONTINUE to continue. 161 * 162 * \since This datatype is available since SDL 3.2.0. 163 */ 164typedef SDL_AppResult (SDLCALL *SDL_AppEvent_func)(void *appstate, SDL_Event *event); 165 166/** 167 * Function pointer typedef for SDL_AppQuit. 168 * 169 * These are used by SDL_EnterAppMainCallbacks. This mechanism operates behind 170 * the scenes for apps using the optional main callbacks. Apps that want to 171 * use this should just implement SDL_AppEvent directly. 172 * 173 * \param appstate an optional pointer, provided by the app in SDL_AppInit. 174 * \param result the result code that terminated the app (success or failure). 175 * 176 * \since This datatype is available since SDL 3.2.0. 177 */ 178typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate, SDL_AppResult result); 179 180 181/** 182 * Initialize the SDL library. 183 * 184 * SDL_Init() simply forwards to calling SDL_InitSubSystem(). Therefore, the 185 * two may be used interchangeably. Though for readability of your code 186 * SDL_InitSubSystem() might be preferred. 187 * 188 * The file I/O (for example: SDL_IOFromFile) and threading (SDL_CreateThread) 189 * subsystems are initialized by default. Message boxes 190 * (SDL_ShowSimpleMessageBox) also attempt to work without initializing the 191 * video subsystem, in hopes of being useful in showing an error dialog when 192 * SDL_Init fails. You must specifically initialize other subsystems if you 193 * use them in your application. 194 * 195 * Logging (such as SDL_Log) works without initialization, too. 196 * 197 * `flags` may be any of the following OR'd together: 198 * 199 * - `SDL_INIT_AUDIO`: audio subsystem; automatically initializes the events 200 * subsystem 201 * - `SDL_INIT_VIDEO`: video subsystem; automatically initializes the events 202 * subsystem, should be initialized on the main thread. 203 * - `SDL_INIT_JOYSTICK`: joystick subsystem; automatically initializes the 204 * events subsystem 205 * - `SDL_INIT_HAPTIC`: haptic (force feedback) subsystem 206 * - `SDL_INIT_GAMEPAD`: gamepad subsystem; automatically initializes the 207 * joystick subsystem 208 * - `SDL_INIT_EVENTS`: events subsystem 209 * - `SDL_INIT_SENSOR`: sensor subsystem; automatically initializes the events 210 * subsystem 211 * - `SDL_INIT_CAMERA`: camera subsystem; automatically initializes the events 212 * subsystem 213 * 214 * Subsystem initialization is ref-counted, you must call SDL_QuitSubSystem() 215 * for each SDL_InitSubSystem() to correctly shutdown a subsystem manually (or 216 * call SDL_Quit() to force shutdown). If a subsystem is already loaded then 217 * this call will increase the ref-count and return. 218 * 219 * Consider reporting some basic metadata about your application before 220 * calling SDL_Init, using either SDL_SetAppMetadata() or 221 * SDL_SetAppMetadataProperty(). 222 * 223 * \param flags subsystem initialization flags. 224 * \returns true on success or false on failure; call SDL_GetError() for more 225 * information. 226 * 227 * \threadsafety This function should only be called on the main thread. 228 * 229 * \since This function is available since SDL 3.2.0. 230 * 231 * \sa SDL_SetAppMetadata 232 * \sa SDL_SetAppMetadataProperty 233 * \sa SDL_InitSubSystem 234 * \sa SDL_Quit 235 * \sa SDL_SetMainReady 236 * \sa SDL_WasInit 237 */ 238extern SDL_DECLSPEC bool SDLCALL SDL_Init(SDL_InitFlags flags); 239 240/** 241 * Compatibility function to initialize the SDL library. 242 * 243 * This function and SDL_Init() are interchangeable. 244 * 245 * \param flags any of the flags used by SDL_Init(); see SDL_Init for details. 246 * \returns true on success or false on failure; call SDL_GetError() for more 247 * information. 248 * 249 * \threadsafety This function should only be called on the main thread. 250 * 251 * \since This function is available since SDL 3.2.0. 252 * 253 * \sa SDL_Init 254 * \sa SDL_Quit 255 * \sa SDL_QuitSubSystem 256 */ 257extern SDL_DECLSPEC bool SDLCALL SDL_InitSubSystem(SDL_InitFlags flags); 258 259/** 260 * Shut down specific SDL subsystems. 261 * 262 * You still need to call SDL_Quit() even if you close all open subsystems 263 * with SDL_QuitSubSystem(). 264 * 265 * \param flags any of the flags used by SDL_Init(); see SDL_Init for details. 266 * 267 * \threadsafety This function is not thread safe. 268 * 269 * \since This function is available since SDL 3.2.0. 270 * 271 * \sa SDL_InitSubSystem 272 * \sa SDL_Quit 273 */ 274extern SDL_DECLSPEC void SDLCALL SDL_QuitSubSystem(SDL_InitFlags flags); 275 276/** 277 * Get a mask of the specified subsystems which are currently initialized. 278 * 279 * \param flags any of the flags used by SDL_Init(); see SDL_Init for details. 280 * \returns a mask of all initialized subsystems if `flags` is 0, otherwise it 281 * returns the initialization status of the specified subsystems. 282 * 283 * \threadsafety This function is not thread safe. 284 * 285 * \since This function is available since SDL 3.2.0. 286 * 287 * \sa SDL_Init 288 * \sa SDL_InitSubSystem 289 */ 290extern SDL_DECLSPEC SDL_InitFlags SDLCALL SDL_WasInit(SDL_InitFlags flags); 291 292/** 293 * Clean up all initialized subsystems. 294 * 295 * You should call this function even if you have already shutdown each 296 * initialized subsystem with SDL_QuitSubSystem(). It is safe to call this 297 * function even in the case of errors in initialization. 298 * 299 * You can use this function with atexit() to ensure that it is run when your 300 * application is shutdown, but it is not wise to do this from a library or 301 * other dynamically loaded code. 302 * 303 * \threadsafety This function should only be called on the main thread. 304 * 305 * \since This function is available since SDL 3.2.0. 306 * 307 * \sa SDL_Init 308 * \sa SDL_QuitSubSystem 309 */ 310extern SDL_DECLSPEC void SDLCALL SDL_Quit(void); 311 312/** 313 * Return whether this is the main thread. 314 * 315 * On Apple platforms, the main thread is the thread that runs your program's 316 * main() entry point. On other platforms, the main thread is the one that 317 * calls SDL_Init(SDL_INIT_VIDEO), which should usually be the one that runs 318 * your program's main() entry point. If you are using the main callbacks, 319 * SDL_AppInit(), SDL_AppIterate(), and SDL_AppQuit() are all called on the 320 * main thread. 321 * 322 * \returns true if this thread is the main thread, or false otherwise. 323 * 324 * \threadsafety It is safe to call this function from any thread. 325 * 326 * \since This function is available since SDL 3.2.0. 327 * 328 * \sa SDL_RunOnMainThread 329 */ 330extern SDL_DECLSPEC bool SDLCALL SDL_IsMainThread(void); 331 332/** 333 * Callback run on the main thread. 334 * 335 * \param userdata an app-controlled pointer that is passed to the callback. 336 * 337 * \since This datatype is available since SDL 3.2.0. 338 * 339 * \sa SDL_RunOnMainThread 340 */ 341typedef void (SDLCALL *SDL_MainThreadCallback)(void *userdata); 342 343/** 344 * Call a function on the main thread during event processing. 345 * 346 * If this is called on the main thread, the callback is executed immediately. 347 * If this is called on another thread, this callback is queued for execution 348 * on the main thread during event processing. 349 * 350 * Be careful of deadlocks when using this functionality. You should not have 351 * the main thread wait for the current thread while this function is being 352 * called with `wait_complete` true. 353 * 354 * \param callback the callback to call on the main thread. 355 * \param userdata a pointer that is passed to `callback`. 356 * \param wait_complete true to wait for the callback to complete, false to 357 * return immediately. 358 * \returns true on success or false on failure; call SDL_GetError() for more 359 * information. 360 * 361 * \threadsafety It is safe to call this function from any thread. 362 * 363 * \since This function is available since SDL 3.2.0. 364 * 365 * \sa SDL_IsMainThread 366 */ 367extern SDL_DECLSPEC bool SDLCALL SDL_RunOnMainThread(SDL_MainThreadCallback callback, void *userdata, bool wait_complete); 368 369/** 370 * Specify basic metadata about your app. 371 * 372 * You can optionally provide metadata about your app to SDL. This is not 373 * required, but strongly encouraged. 374 * 375 * There are several locations where SDL can make use of metadata (an "About" 376 * box in the macOS menu bar, the name of the app can be shown on some audio 377 * mixers, etc). Any piece of metadata can be left as NULL, if a specific 378 * detail doesn't make sense for the app. 379 * 380 * This function should be called as early as possible, before SDL_Init. 381 * Multiple calls to this function are allowed, but various state might not 382 * change once it has been set up with a previous call to this function. 383 * 384 * Passing a NULL removes any previous metadata. 385 * 386 * This is a simplified interface for the most important information. You can 387 * supply significantly more detailed metadata with 388 * SDL_SetAppMetadataProperty(). 389 * 390 * \param appname The name of the application ("My Game 2: Bad Guy's 391 * Revenge!"). 392 * \param appversion The version of the application ("1.0.0beta5" or a git 393 * hash, or whatever makes sense). 394 * \param appidentifier A unique string in reverse-domain format that 395 * identifies this app ("com.example.mygame2"). 396 * \returns true on success or false on failure; call SDL_GetError() for more 397 * information. 398 * 399 * \threadsafety It is safe to call this function from any thread. 400 * 401 * \since This function is available since SDL 3.2.0. 402 * 403 * \sa SDL_SetAppMetadataProperty 404 */ 405extern SDL_DECLSPEC bool SDLCALL SDL_SetAppMetadata(const char *appname, const char *appversion, const char *appidentifier); 406 407/** 408 * Specify metadata about your app through a set of properties. 409 * 410 * You can optionally provide metadata about your app to SDL. This is not 411 * required, but strongly encouraged. 412 * 413 * There are several locations where SDL can make use of metadata (an "About" 414 * box in the macOS menu bar, the name of the app can be shown on some audio 415 * mixers, etc). Any piece of metadata can be left out, if a specific detail 416 * doesn't make sense for the app. 417 * 418 * This function should be called as early as possible, before SDL_Init. 419 * Multiple calls to this function are allowed, but various state might not 420 * change once it has been set up with a previous call to this function. 421 * 422 * Once set, this metadata can be read using SDL_GetAppMetadataProperty(). 423 * 424 * These are the supported properties: 425 * 426 * - `SDL_PROP_APP_METADATA_NAME_STRING`: The human-readable name of the 427 * application, like "My Game 2: Bad Guy's Revenge!". This will show up 428 * anywhere the OS shows the name of the application separately from window 429 * titles, such as volume control applets, etc. This defaults to "SDL 430 * Application". 431 * - `SDL_PROP_APP_METADATA_VERSION_STRING`: The version of the app that is 432 * running; there are no rules on format, so "1.0.3beta2" and "April 22nd, 433 * 2024" and a git hash are all valid options. This has no default. 434 * - `SDL_PROP_APP_METADATA_IDENTIFIER_STRING`: A unique string that 435 * identifies this app. This must be in reverse-domain format, like 436 * "com.example.mygame2". This string is used by desktop compositors to 437 * identify and group windows together, as well as match applications with 438 * associated desktop settings and icons. If you plan to package your 439 * application in a container such as Flatpak, the app ID should match the 440 * name of your Flatpak container as well. This has no default. 441 * - `SDL_PROP_APP_METADATA_CREATOR_STRING`: The human-readable name of the 442 * creator/developer/maker of this app, like "MojoWorkshop, LLC" 443 * - `SDL_PROP_APP_METADATA_COPYRIGHT_STRING`: The human-readable copyright 444 * notice, like "Copyright (c) 2024 MojoWorkshop, LLC" or whatnot. Keep this 445 * to one line, don't paste a copy of a whole software license in here. This 446 * has no default. 447 * - `SDL_PROP_APP_METADATA_URL_STRING`: A URL to the app on the web. Maybe a 448 * product page, or a storefront, or even a GitHub repository, for user's 449 * further information This has no default. 450 * - `SDL_PROP_APP_METADATA_TYPE_STRING`: The type of application this is. 451 * Currently this string can be "game" for a video game, "mediaplayer" for a 452 * media player, or generically "application" if nothing else applies. 453 * Future versions of SDL might add new types. This defaults to 454 * "application". 455 * 456 * \param name the name of the metadata property to set. 457 * \param value the value of the property, or NULL to remove that property. 458 * \returns true on success or false on failure; call SDL_GetError() for more 459 * information. 460 * 461 * \threadsafety It is safe to call this function from any thread. 462 * 463 * \since This function is available since SDL 3.2.0. 464 * 465 * \sa SDL_GetAppMetadataProperty 466 * \sa SDL_SetAppMetadata 467 */ 468extern SDL_DECLSPEC bool SDLCALL SDL_SetAppMetadataProperty(const char *name, const char *value); 469 470#define SDL_PROP_APP_METADATA_NAME_STRING "SDL.app.metadata.name" 471#define SDL_PROP_APP_METADATA_VERSION_STRING "SDL.app.metadata.version" 472#define SDL_PROP_APP_METADATA_IDENTIFIER_STRING "SDL.app.metadata.identifier" 473#define SDL_PROP_APP_METADATA_CREATOR_STRING "SDL.app.metadata.creator" 474#define SDL_PROP_APP_METADATA_COPYRIGHT_STRING "SDL.app.metadata.copyright" 475#define SDL_PROP_APP_METADATA_URL_STRING "SDL.app.metadata.url" 476#define SDL_PROP_APP_METADATA_TYPE_STRING "SDL.app.metadata.type" 477 478/** 479 * Get metadata about your app. 480 * 481 * This returns metadata previously set using SDL_SetAppMetadata() or 482 * SDL_SetAppMetadataProperty(). See SDL_SetAppMetadataProperty() for the list 483 * of available properties and their meanings. 484 * 485 * \param name the name of the metadata property to get. 486 * \returns the current value of the metadata property, or the default if it 487 * is not set, NULL for properties with no default. 488 * 489 * \threadsafety It is safe to call this function from any thread, although 490 * the string returned is not protected and could potentially be 491 * freed if you call SDL_SetAppMetadataProperty() to set that 492 * property from another thread. 493 * 494 * \since This function is available since SDL 3.2.0. 495 * 496 * \sa SDL_SetAppMetadata 497 * \sa SDL_SetAppMetadataProperty 498 */ 499extern SDL_DECLSPEC const char * SDLCALL SDL_GetAppMetadataProperty(const char *name); 500 501/* Ends C function definitions when using C++ */ 502#ifdef __cplusplus 503} 504#endif 505#include <SDL3/SDL_close_code.h> 506 507#endif /* SDL_init_h_ */ 508
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.