SDL 3.0
SDL_init.h File Reference
+ Include dependency graph for SDL_init.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SDL_INIT_TIMER   0x00000001u
 
#define SDL_INIT_AUDIO   0x00000010u
 
#define SDL_INIT_VIDEO   0x00000020u
 
#define SDL_INIT_JOYSTICK   0x00000200u
 
#define SDL_INIT_HAPTIC   0x00001000u
 
#define SDL_INIT_GAMEPAD   0x00002000u
 
#define SDL_INIT_EVENTS   0x00004000u
 
#define SDL_INIT_SENSOR   0x00008000u
 
#define SDL_INIT_CAMERA   0x00010000u
 
#define SDL_PROP_APP_METADATA_NAME_STRING   "SDL.app.metadata.name"
 
#define SDL_PROP_APP_METADATA_VERSION_STRING   "SDL.app.metadata.version"
 
#define SDL_PROP_APP_METADATA_IDENTIFIER_STRING   "SDL.app.metadata.identifier"
 
#define SDL_PROP_APP_METADATA_CREATOR_STRING   "SDL.app.metadata.creator"
 
#define SDL_PROP_APP_METADATA_COPYRIGHT_STRING   "SDL.app.metadata.copyright"
 
#define SDL_PROP_APP_METADATA_URL_STRING   "SDL.app.metadata.url"
 
#define SDL_PROP_APP_METADATA_TYPE_STRING   "SDL.app.metadata.type"
 

Typedefs

typedef Uint32 SDL_InitFlags
 

Functions

int SDL_Init (SDL_InitFlags flags)
 
int SDL_InitSubSystem (SDL_InitFlags flags)
 
void SDL_QuitSubSystem (SDL_InitFlags flags)
 
SDL_InitFlags SDL_WasInit (SDL_InitFlags flags)
 
void SDL_Quit (void)
 
int SDL_SetAppMetadata (const char *appname, const char *appversion, const char *appidentifier)
 
int SDL_SetAppMetadataProperty (const char *name, const char *value)
 
const char * SDL_GetAppMetadataProperty (const char *name)
 

Macro Definition Documentation

◆ SDL_INIT_AUDIO

#define SDL_INIT_AUDIO   0x00000010u

SDL_INIT_AUDIO implies SDL_INIT_EVENTS

Definition at line 60 of file SDL_init.h.

◆ SDL_INIT_CAMERA

#define SDL_INIT_CAMERA   0x00010000u

SDL_INIT_CAMERA implies SDL_INIT_EVENTS

Definition at line 67 of file SDL_init.h.

◆ SDL_INIT_EVENTS

#define SDL_INIT_EVENTS   0x00004000u

Definition at line 65 of file SDL_init.h.

◆ SDL_INIT_GAMEPAD

#define SDL_INIT_GAMEPAD   0x00002000u

SDL_INIT_GAMEPAD implies SDL_INIT_JOYSTICK

Definition at line 64 of file SDL_init.h.

◆ SDL_INIT_HAPTIC

#define SDL_INIT_HAPTIC   0x00001000u

Definition at line 63 of file SDL_init.h.

◆ SDL_INIT_JOYSTICK

#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

Definition at line 62 of file SDL_init.h.

◆ SDL_INIT_SENSOR

#define SDL_INIT_SENSOR   0x00008000u

SDL_INIT_SENSOR implies SDL_INIT_EVENTS

Definition at line 66 of file SDL_init.h.

◆ SDL_INIT_TIMER

#define SDL_INIT_TIMER   0x00000001u

Definition at line 59 of file SDL_init.h.

◆ SDL_INIT_VIDEO

#define SDL_INIT_VIDEO   0x00000020u

SDL_INIT_VIDEO implies SDL_INIT_EVENTS

Definition at line 61 of file SDL_init.h.

◆ SDL_PROP_APP_METADATA_COPYRIGHT_STRING

#define SDL_PROP_APP_METADATA_COPYRIGHT_STRING   "SDL.app.metadata.copyright"

Definition at line 296 of file SDL_init.h.

◆ SDL_PROP_APP_METADATA_CREATOR_STRING

#define SDL_PROP_APP_METADATA_CREATOR_STRING   "SDL.app.metadata.creator"

Definition at line 295 of file SDL_init.h.

◆ SDL_PROP_APP_METADATA_IDENTIFIER_STRING

#define SDL_PROP_APP_METADATA_IDENTIFIER_STRING   "SDL.app.metadata.identifier"

Definition at line 294 of file SDL_init.h.

◆ SDL_PROP_APP_METADATA_NAME_STRING

#define SDL_PROP_APP_METADATA_NAME_STRING   "SDL.app.metadata.name"

Definition at line 292 of file SDL_init.h.

◆ SDL_PROP_APP_METADATA_TYPE_STRING

#define SDL_PROP_APP_METADATA_TYPE_STRING   "SDL.app.metadata.type"

Definition at line 298 of file SDL_init.h.

◆ SDL_PROP_APP_METADATA_URL_STRING

#define SDL_PROP_APP_METADATA_URL_STRING   "SDL.app.metadata.url"

Definition at line 297 of file SDL_init.h.

◆ SDL_PROP_APP_METADATA_VERSION_STRING

#define SDL_PROP_APP_METADATA_VERSION_STRING   "SDL.app.metadata.version"

Definition at line 293 of file SDL_init.h.

Typedef Documentation

◆ SDL_InitFlags

CategoryInit

SDL subsystem init and quit functions. Initialization flags for SDL_Init and/or SDL_InitSubSystem

These are the flags which may be passed to SDL_Init(). You should specify the subsystems which you will be using in your application.

Since
This datatype is available since SDL 3.0.0.
See also
SDL_Init
SDL_Quit
SDL_InitSubSystem
SDL_QuitSubSystem
SDL_WasInit

Definition at line 57 of file SDL_init.h.

Function Documentation

◆ SDL_GetAppMetadataProperty()

const char * SDL_GetAppMetadataProperty ( const char *  name)
extern

Get metadata about your app.

This returns metadata previously set using SDL_SetAppMetadata() or SDL_SetAppMetadataProperty(). See SDL_SetAppMetadataProperty() for the list of available properties and their meanings.

Parameters
namethe name of the metadata property to get.
Returns
the current value of the metadata property, or the default if it is not set, NULL for properties with no default.

\threadsafety It is safe to call this function from any thread, although the string returned is not protected and could potentially be freed if you call SDL_SetAppMetadataProperty() to set that property from another thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_SetAppMetadata
SDL_SetAppMetadataProperty

◆ SDL_Init()

int SDL_Init ( SDL_InitFlags  flags)
extern

Initialize the SDL library.

SDL_Init() simply forwards to calling SDL_InitSubSystem(). Therefore, the two may be used interchangeably. Though for readability of your code SDL_InitSubSystem() might be preferred.

The file I/O (for example: SDL_IOFromFile) and threading (SDL_CreateThread) subsystems are initialized by default. 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. You must specifically initialize other subsystems if you use them in your application.

Logging (such as SDL_Log) works without initialization, too.

flags may be any of the following OR'd together:

  • SDL_INIT_TIMER: timer subsystem
  • SDL_INIT_AUDIO: audio subsystem; automatically initializes the events subsystem
  • SDL_INIT_VIDEO: video subsystem; automatically initializes the events subsystem
  • SDL_INIT_JOYSTICK: joystick subsystem; automatically initializes the events subsystem
  • SDL_INIT_HAPTIC: haptic (force feedback) subsystem
  • 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, 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.

Consider reporting some basic metadata about your application before calling SDL_Init, using either SDL_SetAppMetadata() or SDL_SetAppMetadataProperty().

Parameters
flagssubsystem initialization flags.
Returns
0 on success or a negative error code on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetAppMetadata
SDL_SetAppMetadataProperty
SDL_InitSubSystem
SDL_Quit
SDL_SetMainReady
SDL_WasInit

◆ SDL_InitSubSystem()

int SDL_InitSubSystem ( SDL_InitFlags  flags)
extern

Compatibility function to initialize the SDL library.

This function and SDL_Init() are interchangeable.

Parameters
flagsany of the flags used by SDL_Init(); see SDL_Init for details.
Returns
0 on success or a negative error code on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_Init
SDL_Quit
SDL_QuitSubSystem

◆ SDL_Quit()

void SDL_Quit ( void  )
extern

Clean up all initialized subsystems.

You should call this function even if you have already shutdown each initialized subsystem with SDL_QuitSubSystem(). It is safe to call this function even in the case of errors in initialization.

You can use this function with atexit() to ensure that it is run when your application is shutdown, but it is not wise to do this from a library or other dynamically loaded code.

Since
This function is available since SDL 3.0.0.
See also
SDL_Init
SDL_QuitSubSystem

◆ SDL_QuitSubSystem()

void SDL_QuitSubSystem ( SDL_InitFlags  flags)
extern

Shut down specific SDL subsystems.

You still need to call SDL_Quit() even if you close all open subsystems with SDL_QuitSubSystem().

Parameters
flagsany of the flags used by SDL_Init(); see SDL_Init for details.
Since
This function is available since SDL 3.0.0.
See also
SDL_InitSubSystem
SDL_Quit

◆ SDL_SetAppMetadata()

int SDL_SetAppMetadata ( const char *  appname,
const char *  appversion,
const char *  appidentifier 
)
extern

Specify basic metadata about your app.

You can optionally provide metadata about your app to SDL. This is not required, but strongly encouraged.

There are several locations where SDL can make use of metadata (an "About" box in the macOS menu bar, the name of the app can be shown on some audio mixers, etc). Any piece of metadata can be left as NULL, if a specific detail doesn't make sense for the app.

This function should be called as early as possible, before SDL_Init. Multiple calls to this function are allowed, but various state might not change once it has been set up with a previous call to this function.

Passing a NULL removes any previous metadata.

This is a simplified interface for the most important information. You can supply significantly more detailed metadata with SDL_SetAppMetadataProperty().

Parameters
appnameThe name of the application ("My Game 2: Bad Guy's Revenge!").
appversionThe version of the application ("1.0.0beta5" or a git hash, or whatever makes sense).
appidentifierA unique string in reverse-domain format that identifies this app ("com.example.mygame2").
Returns
0 on success or a negative error code on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_SetAppMetadataProperty

◆ SDL_SetAppMetadataProperty()

int SDL_SetAppMetadataProperty ( const char *  name,
const char *  value 
)
extern

Specify metadata about your app through a set of properties.

You can optionally provide metadata about your app to SDL. This is not required, but strongly encouraged.

There are several locations where SDL can make use of metadata (an "About" box in the macOS menu bar, the name of the app can be shown on some audio mixers, etc). Any piece of metadata can be left out, if a specific detail doesn't make sense for the app.

This function should be called as early as possible, before SDL_Init. Multiple calls to this function are allowed, but various state might not change once it has been set up with a previous call to this function.

Once set, this metadata can be read using SDL_GetMetadataProperty().

These are the supported properties:

  • SDL_PROP_APP_METADATA_NAME_STRING: The human-readable name of the application, like "My Game 2: Bad Guy's Revenge!". This will show up anywhere the OS shows the name of the application separately from window titles, such as volume control applets, etc. This defaults to "SDL Application".
  • SDL_PROP_APP_METADATA_VERSION_STRING: The version of the app that is running; there are no rules on format, so "1.0.3beta2" and "April 22nd, 2024" and a git hash are all valid options. This has no default. -SDL_PROP_APP_METADATA_IDENTIFIER_STRING: A unique string that identifies this app. This must be in reverse-domain format, like "com.example.mygame2". This string is used by desktop compositors to identify and group windows together, as well as match applications with associated desktop settings and icons. If you plan to package your application in a container such as Flatpak, the app ID should match the name of your Flatpak container as well. This has no default.
  • SDL_PROP_APP_METADATA_CREATOR_STRING: The human-readable name of the creator/developer/maker of this app, like "MojoWorkshop, LLC"
  • SDL_PROP_APP_METADATA_COPYRIGHT_STRING: The human-readable copyright notice, like "Copyright (c) 2024 MojoWorkshop, LLC" or whatnot. Keep this to one line, don't paste a copy of a whole software license in here. This has no default.
  • SDL_PROP_APP_METADATA_URL_STRING: A URL to the app on the web. Maybe a product page, or a storefront, or even a GitHub repository, for user's further information This has no default.
  • SDL_PROP_APP_METADATA_TYPE_STRING`: The type of application this is. Currently this string can be "game" for a video game, "mediaplayer" for a media player, or generically "application" if nothing else applies. Future versions of SDL might add new types. This defaults to "application".
Parameters
namethe name of the metadata property to set.
valuethe value of the property, or NULL to remove that property.
Returns
0 on success or a negative error code on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_GetAppMetadataProperty
SDL_SetAppMetadata

◆ SDL_WasInit()

SDL_InitFlags SDL_WasInit ( SDL_InitFlags  flags)
extern

Get a mask of the specified subsystems which are currently initialized.

Parameters
flagsany of the flags used by SDL_Init(); see SDL_Init for details.
Returns
a mask of all initialized subsystems if flags is 0, otherwise it returns the initialization status of the specified subsystems.
Since
This function is available since SDL 3.0.0.
See also
SDL_Init
SDL_InitSubSystem