SDL_Init(3)
๐ SDL_Init โ bestie edition ๐
okay so we're in the SDL3 FUNCTIONS section of the SDL_Init(3) manual and honestly? this one is a whole vibe. it's the "wake up babe, we're initializing" function. let's get into it ๐ซถ
โจ NAME โจ
SDL_Init โ Initialize the SDL library. that's it, that's the whole job. she wakes the library up ๐
๐ธ SYNOPSIS ๐ธ
#include <SDL3/SDL_init.h>
bool SDL_Init(SDL_InitFlags flags);
like, that's the entire thing. one function, one flag argument, and then the party starts ๐
๐ฆ DESCRIPTION ๐ฆ
okay so here's the tea: SDL_Init() literally just forwards to calling SDL_InitSubSystem(). no cap. they are interchangeable, fr fr. but โ and this is the girlypop coding-taste part โ for readability of your code, SDL_InitSubSystem() might be the one you prefer. it's giving "clear communication" โจ
now the important bit, listen up ๐
- file I/O (for example:
SDL_IOFromFile) and threading (SDL_CreateThread) subsystems are initialized by default. you don't gotta do anything, they just show up ๐ - message boxes (
SDL_ShowSimpleMessageBox) also attempt to work without initializing the video subsystem, in hopes of being useful in showing an error dialog whenSDL_Initfails. so thoughtful of her, honestly ๐ญ - you must specifically initialize other subsystems if you use them in your application. no mind-reading here bestie
- logging (such as
SDL_Log) works without initialization, too. main character energy, doesn't need permission ๐
flags may be any of the following OR'd together. yes, OR'd โ like stacking accessories, you can wear more than one ๐
SDL_INIT_AUDIOโ audio subsystem; automatically initializes the events subsystem ๐SDL_INIT_VIDEOโ video subsystem; automatically initializes the events subsystem, and should be initialized on the main thread. (main thread!! don't be messy about it ๐จ)SDL_INIT_JOYSTICKโ joystick subsystem; automatically initializes the events subsystem ๐น๏ธSDL_INIT_HAPTICโ haptic (force feedback) subsystem. yes, the rumbly one ๐ซSDL_INIT_GAMEPADโ gamepad subsystem; automatically initializes the joystick subsystem ๐ฎSDL_INIT_EVENTSโ events subsystem ๐ฌSDL_INIT_SENSORโ sensor subsystem; automatically initializes the events subsystem ๐ก๏ธSDL_INIT_CAMERAโ camera subsystem; automatically initializes the events subsystem ๐ธ
subsystem initialization is ref-counted, bestie. so you must call SDL_QuitSubSystem() for each SDL_InitSubSystem() to correctly shutdown a subsystem manually (or call SDL_Quit() to force shutdown, if you're feeling dramatic ๐). and if a subsystem is already loaded, then this call will increase the ref-count and return. it's just counting, she's not gonna redo the work ๐
also โ cute little suggestion โ consider reporting some basic metadata about your application before calling SDL_Init, using either SDL_SetAppMetadata() or SDL_SetAppMetadataProperty(). it's giving "introduce yourself before you walk in" ๐ธ
๐ FUNCTION PARAMETERS ๐
flagsโ subsystem initialization flags. the little wishlist of what you want woken up.
๐ RETURN VALUE ๐
returns true on success or false on failure. if it's a fail, call SDL_GetError() for more information โ she'll tell you what went wrong, she's not gatekeeping ๐
๐ THREAD SAFETY ๐
this function should only be called on the main thread. no side-quests, no background threads, no exceptions. periodt. ๐ซ
๐ AVAILABILITY ๐
this function is available since SDL 3.2.0. iconic, we've had her for a minute ๐
๐ฅ SEE ALSO ๐ฅ
SDL_SetAppMetadata(3)SDL_SetAppMetadataProperty(3)SDL_InitSubSystem(3)SDL_Quit(3)SDL_SetMainReady(3)SDL_WasInit(3)
and that's the whole page, bestie!! this one came to you from Simple Directmedia Layer, for <b>SDL 3.4.18</b>, and yeah the SDL_Init(3) girlies know exactly what time it is. go forth and initialize responsibly ๐ซถโจ๐
๐ฆ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 ยท Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 ยท Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 ยท Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 ยท Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms