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 when SDL_Init fails. 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 ๐Ÿ”ฅ


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