On this page:
4.1 Initialization Syntax
with-sdl
4.2 Initialization Functions
sdl-init!
sdl-quit!
sdl-init-subsystem!
sdl-quit-subsystem!
sdl-was-init
error-message
4.3 Application Metadata
set-app-metadata!
set-app-metadata-property!
get-app-metadata-property
9.0.0.11

4 Initialization🔗ℹ

Before using any SDL3 functions, the library must be initialized. The safe API provides both syntax forms and procedural functions.

4.1 Initialization Syntax🔗ℹ

syntax

(with-sdl maybe-flags body ...)

 
maybe-flags = 
  | #:flags flags
 
  flags : (or/c symbol? (listof symbol?))
Initializes SDL, evaluates body forms, then shuts down SDL. This is the recommended way to structure an SDL program.

By default, initializes the video subsystem. Use #:flags to initialize specific subsystems:
  • 'video Video subsystem (default)

  • 'audio Audio subsystem

  • 'events Events subsystem

  • 'joystick Joystick subsystem

  • 'gamepad Gamepad subsystem

  • 'camera Camera subsystem

(with-sdl
  (displayln "SDL is ready!")
  ;; ... your SDL code here ...
  )
 
(with-sdl #:flags '(video audio)
  ;; Both video and audio are available
  )

4.2 Initialization Functions🔗ℹ

procedure

(sdl-init! [flags])  void?

  flags : (or/c symbol? (listof symbol?)) = 'video
Initializes SDL with the specified subsystems. Raises an error if initialization fails.

flags can be a single symbol or a list of symbols. See with-sdl for available flags.

(sdl-init!)              ; Initialize video only
(sdl-init! 'audio)       ; Initialize audio only
(sdl-init! '(video audio)) ; Initialize both

procedure

(sdl-quit!)  void?

Shuts down all SDL subsystems. Call this when your program is done using SDL. If using with-sdl, this is called automatically.

procedure

(sdl-init-subsystem! flags)  void?

  flags : (or/c symbol? (listof symbol?))
Initializes additional subsystems after SDL has already been initialized. Useful for lazily initializing subsystems as needed.

procedure

(sdl-quit-subsystem! flags)  void?

  flags : (or/c symbol? (listof symbol?))
Shuts down specific subsystems while keeping others running.

procedure

(sdl-was-init [flags])  exact-nonnegative-integer?

  flags : exact-nonnegative-integer? = 0
Returns a bitmask of which subsystems are currently initialized. If flags is 0, returns all initialized subsystems.

procedure

(error-message)  string?

Returns the last SDL error message. Useful for debugging when an operation fails.

4.3 Application Metadata🔗ℹ

procedure

(set-app-metadata! name version identifier)  void?

  name : string?
  version : string?
  identifier : string?
Sets application metadata used by the operating system. Should be called before creating windows.

  • name Human-readable application name

  • version Version string (e.g., "1.0.0")

  • identifier Unique identifier (e.g., "com.example.myapp")

procedure

(set-app-metadata-property! name value)  void?

  name : string?
  value : string?
Sets a specific metadata property. Use the SDL_PROP_APP_METADATA_* constants for property names.

procedure

(get-app-metadata-property name)  (or/c string? #f)

  name : string?
Gets a metadata property value, or #f if not set.