sdl
| Kind | ffi-c |
|---|---|
| Capabilities | ffi |
| Categories | multimedia graphics gamedev |
| Keywords | sdl sdl2 window input graphics gamedev |
SDL2 bindings for Kit - cross-platform windowing, input, and graphics
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
c/kit_sdl.c | C FFI wrapper around SDL2 |
c/kit_sdl.h | C header for the FFI wrapper |
examples/animation.kit | Animated rectangle example with pause and reset input |
examples/basic.kit | Basic window, renderer, events, and primitive drawing example |
examples/basic_image/basic_image.kit | SDL2-core shape grid equivalent for image-style rendering |
examples/basic_mixer/basic_mixer.kit | SDL2-core audio driver and device discovery example |
examples/basic_window/basic_window.kit | Minimal window creation example |
examples/input.kit | Keyboard, mouse, and polling input example |
examples/lbm/lbm.kit | Lightweight fluid-visualization style rendering example |
examples/native-window-info-probe.kit | Native window-handle probe for backend integration |
examples/tvintris/tvintris.kit | Small Tetris-like rendering and input example |
examples/version/version.kit | SDL version query example |
examples/versions/versions.kit | SDL version information example |
kit.toml | Package manifest, native linker settings, capabilities, and tasks |
src/internal/types.kit | Internal record aliases used by exported SDL helpers |
src/sdl.kit | Public SDL module exposed as Kit.Sdl |
tests/sdl-properties.test.kit | Record and property-pattern tests |
tests/sdl.test.kit | SDL constants, event, helper, and game-loop pattern tests |
Dependencies
No Kit package dependencies.
Native dependency:
| Platform | Install |
|---|---|
| macOS | brew install sdl2 |
| Ubuntu/Debian | sudo apt-get install libsdl2-dev |
This package is an FFI package and requires the ffi capability when running examples directly.
Installation
kit add gitlab.com/kit-lang/packages/kit-sdl.gitUsage
import Kit.Sdl as SDL
main = fn =>
match SDL.init
| Err err ->
print "SDL init failed: ${err}"
| Ok _ ->
defer SDL.quit
match SDL.create-window "Kit SDL Demo" 800 600
| Err err ->
print "Window error: ${err}"
| Ok window ->
defer SDL.destroy-window window
match SDL.create-renderer window
| Err err ->
print "Renderer error: ${err}"
| Ok renderer ->
defer SDL.destroy-renderer renderer
SDL.set-draw-color renderer 30 30 40 255
SDL.clear renderer
SDL.set-draw-color renderer 100 200 100 255
SDL.fill-rect renderer 100 100 240 160
SDL.present renderer
SDL.delay 1000
mainThe public module includes helpers for:
| Area | Examples |
|---|---|
| Initialization | init, init-video, init-audio, quit |
| Windows and renderers | create-window, destroy-window, create-renderer, destroy-renderer |
| Drawing | set-draw-color, clear, present, draw-line, draw-rect, fill-rect, draw-point |
| Events and input | poll-event, is-key-pressed?, get-mouse-x, get-mouse-y, scancode constants |
| Display and high DPI | get-num-displays, drawable-size, drawable-scale, display-scale |
| Audio | get-num-audio-drivers, get-current-audio-driver, get-num-audio-devices |
| Devices | joystick, game controller, haptic, touch, and sensor helpers |
| Platform integration | native-window-info, prepare-macos-gui-app, SDL version and platform queries |
Most resource-creating functions return Result values. Pair successful handles with defer cleanup, as shown above, so examples and tests stay reliable when an error branch is hit.
Development
Running Examples
Run examples with the interpreter:
kit run --allow=ffi examples/basic.kitCompile an example to a native binary:
kit build examples/basic.kit --allow=ffi && ./basicThe nested example files use unique basenames, such as basic_image.kit and basic_mixer.kit, so parity builds do not overwrite multiple main binaries in a shared temporary directory.
Running Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow:
kit dev --no-spinnerThis will:
- Build or reuse the native SDL wrapper library
- Check formatting
- Type check source and examples
- Run tests with coverage
Running Parity
Check interpreter/compiler parity for examples:
kit parity --no-spinner --failures-onlyThe examples are written to terminate deterministically after a small number of frames when no SDL quit event is received. That keeps parity and CI runs from waiting on interactive input while preserving the event-handling paths for real use.
Generating Documentation
Generate API documentation from doc comments:
kit docKit sources with doc comments (##) generate HTML documents in docs/*.html.
Cleaning Build Artifacts
Remove generated files, caches, parity results, and native build artifacts:
kit task cleanThe clean task is defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis installs the package to ~/.kit/packages/@kit/sdl/, making it available for import as Kit.Sdl in other projects.
License
This package is released under the MIT License - see LICENSE for details.
SDL2 is distributed under the zlib License.
Exported Functions & Types
event-quit
SDL constant event-quit.
event-keydown
SDL constant event-keydown.
event-keyup
SDL constant event-keyup.
event-mousemotion
SDL constant event-mousemotion.
event-mousebuttondown
SDL constant event-mousebuttondown.
event-mousebuttonup
SDL constant event-mousebuttonup.
event-mousewheel
SDL constant event-mousewheel.
event-windowevent
SDL constant event-windowevent.
windowevent-shown
SDL constant windowevent-shown.
windowevent-hidden
SDL constant windowevent-hidden.
windowevent-exposed
SDL constant windowevent-exposed.
windowevent-moved
SDL constant windowevent-moved.
windowevent-resized
SDL constant windowevent-resized.
windowevent-size-changed
SDL constant windowevent-size-changed.
windowevent-minimized
SDL constant windowevent-minimized.
windowevent-maximized
SDL constant windowevent-maximized.
windowevent-restored
SDL constant windowevent-restored.
windowevent-enter
SDL constant windowevent-enter.
windowevent-leave
SDL constant windowevent-leave.
windowevent-focus-gained
SDL constant windowevent-focus-gained.
windowevent-focus-lost
SDL constant windowevent-focus-lost.
windowevent-close
SDL constant windowevent-close.
windowevent-take-focus
SDL constant windowevent-take-focus.
windowevent-hit-test
SDL constant windowevent-hit-test.
windowevent-iccprof-changed
SDL constant windowevent-iccprof-changed.
windowevent-display-changed
SDL constant windowevent-display-changed.
button-left
SDL constant button-left.
button-middle
SDL constant button-middle.
button-right
SDL constant button-right.
kmod-none
SDL constant kmod-none.
kmod-lshift
SDL constant kmod-lshift.
kmod-rshift
SDL constant kmod-rshift.
kmod-lctrl
SDL constant kmod-lctrl.
kmod-rctrl
SDL constant kmod-rctrl.
kmod-lalt
SDL constant kmod-lalt.
kmod-ralt
SDL constant kmod-ralt.
kmod-lgui
SDL constant kmod-lgui.
kmod-rgui
SDL constant kmod-rgui.
kmod-caps
SDL constant kmod-caps.
kmod-num
SDL constant kmod-num.
scancode-a
SDL constant scancode-a.
scancode-b
SDL constant scancode-b.
scancode-c
SDL constant scancode-c.
scancode-d
SDL constant scancode-d.
scancode-e
SDL constant scancode-e.
scancode-f
SDL constant scancode-f.
scancode-g
SDL constant scancode-g.
scancode-h
SDL constant scancode-h.
scancode-i
SDL constant scancode-i.
scancode-j
SDL constant scancode-j.
scancode-k
SDL constant scancode-k.
scancode-l
SDL constant scancode-l.
scancode-m
SDL constant scancode-m.
scancode-n
SDL constant scancode-n.
scancode-o
SDL constant scancode-o.
scancode-p
SDL constant scancode-p.
scancode-q
SDL constant scancode-q.
scancode-r
SDL constant scancode-r.
scancode-s
SDL constant scancode-s.
scancode-t
SDL constant scancode-t.
scancode-u
SDL constant scancode-u.
scancode-v
SDL constant scancode-v.
scancode-w
SDL constant scancode-w.
scancode-x
SDL constant scancode-x.
scancode-y
SDL constant scancode-y.
scancode-z
SDL constant scancode-z.
scancode-1
SDL constant scancode-1.
scancode-2
SDL constant scancode-2.
scancode-3
SDL constant scancode-3.
scancode-4
SDL constant scancode-4.
scancode-5
SDL constant scancode-5.
scancode-6
SDL constant scancode-6.
scancode-7
SDL constant scancode-7.
scancode-8
SDL constant scancode-8.
scancode-9
SDL constant scancode-9.
scancode-0
SDL constant scancode-0.
scancode-return
SDL constant scancode-return.
scancode-escape
SDL constant scancode-escape.
scancode-backspace
SDL constant scancode-backspace.
scancode-tab
SDL constant scancode-tab.
scancode-space
SDL constant scancode-space.
scancode-pageup
SDL constant scancode-pageup.
scancode-pagedown
SDL constant scancode-pagedown.
scancode-right
SDL constant scancode-right.
scancode-left
SDL constant scancode-left.
scancode-down
SDL constant scancode-down.
scancode-up
SDL constant scancode-up.
scancode-f1
SDL constant scancode-f1.
scancode-f2
SDL constant scancode-f2.
scancode-f3
SDL constant scancode-f3.
scancode-f4
SDL constant scancode-f4.
scancode-f5
SDL constant scancode-f5.
scancode-f6
SDL constant scancode-f6.
scancode-f7
SDL constant scancode-f7.
scancode-f8
SDL constant scancode-f8.
scancode-f9
SDL constant scancode-f9.
scancode-f10
SDL constant scancode-f10.
scancode-f11
SDL constant scancode-f11.
scancode-f12
SDL constant scancode-f12.
controller-axis-leftx
SDL constant controller-axis-leftx.
controller-axis-lefty
SDL constant controller-axis-lefty.
controller-axis-rightx
SDL constant controller-axis-rightx.
controller-axis-righty
SDL constant controller-axis-righty.
controller-axis-triggerleft
SDL constant controller-axis-triggerleft.
controller-axis-triggerright
SDL constant controller-axis-triggerright.
controller-button-a
SDL constant controller-button-a.
controller-button-b
SDL constant controller-button-b.
controller-button-x
SDL constant controller-button-x.
controller-button-y
SDL constant controller-button-y.
controller-button-back
SDL constant controller-button-back.
controller-button-guide
SDL constant controller-button-guide.
controller-button-start
SDL constant controller-button-start.
controller-button-leftstick
SDL constant controller-button-leftstick.
controller-button-rightstick
SDL constant controller-button-rightstick.
controller-button-leftshoulder
SDL constant controller-button-leftshoulder.
controller-button-rightshoulder
SDL constant controller-button-rightshoulder.
controller-button-dpad-up
SDL constant controller-button-dpad-up.
controller-button-dpad-down
SDL constant controller-button-dpad-down.
controller-button-dpad-left
SDL constant controller-button-dpad-left.
controller-button-dpad-right
SDL constant controller-button-dpad-right.
window-shown
SDL constant window-shown.
window-hidden
SDL constant window-hidden.
window-borderless
SDL constant window-borderless.
window-resizable
SDL constant window-resizable.
window-minimized
SDL constant window-minimized.
window-maximized
SDL constant window-maximized.
window-fullscreen
SDL constant window-fullscreen.
window-fullscreen-desktop
SDL constant window-fullscreen-desktop.
window-opengl
SDL constant window-opengl.
window-input-focus
SDL constant window-input-focus.
window-mouse-focus
SDL constant window-mouse-focus.
window-allow-highdpi
SDL constant window-allow-highdpi.
syswm-unknown
SDL constant syswm-unknown.
syswm-windows
SDL constant syswm-windows.
syswm-x11
SDL constant syswm-x11.
syswm-directfb
SDL constant syswm-directfb.
syswm-cocoa
SDL constant syswm-cocoa.
syswm-uikit
SDL constant syswm-uikit.
syswm-wayland
SDL constant syswm-wayland.
syswm-mir
SDL constant syswm-mir.
syswm-winrt
SDL constant syswm-winrt.
syswm-android
SDL constant syswm-android.
syswm-vivante
SDL constant syswm-vivante.
syswm-os2
SDL constant syswm-os2.
syswm-haiku
SDL constant syswm-haiku.
syswm-kmsdrm
SDL constant syswm-kmsdrm.
syswm-riscos
SDL constant syswm-riscos.
event-textinput
SDL constant event-textinput.
event-textediting
SDL constant event-textediting.
event-dropfile
SDL constant event-dropfile.
event-droptext
SDL constant event-droptext.
event-dropbegin
SDL constant event-dropbegin.
event-dropcomplete
SDL constant event-dropcomplete.
event-controlleraxismotion
SDL constant event-controlleraxismotion.
event-controllerbuttondown
SDL constant event-controllerbuttondown.
event-controllerbuttonup
SDL constant event-controllerbuttonup.
event-controllerdeviceadded
SDL constant event-controllerdeviceadded.
event-controllerdeviceremoved
SDL constant event-controllerdeviceremoved.
event-joyaxismotion
SDL constant event-joyaxismotion.
event-joybuttondown
SDL constant event-joybuttondown.
event-joybuttonup
SDL constant event-joybuttonup.
event-joyhatmotion
SDL constant event-joyhatmotion.
event-joydeviceadded
SDL constant event-joydeviceadded.
event-joydeviceremoved
SDL constant event-joydeviceremoved.
event-fingerdown
SDL constant event-fingerdown.
event-fingerup
SDL constant event-fingerup.
event-fingermotion
SDL constant event-fingermotion.
event-multigesture
SDL constant event-multigesture.
Event
Typed SDL event normalized from a raw event record.
Variants
QuitKeyDown {scancode, keycode, mods, repeat?}KeyUp {scancode, keycode, mods, repeat?}TextInput {text}TextEditing {text, start, length}MouseMotion {x, y, rel-x, rel-y}MouseButtonDown {x, y, button, clicks}MouseButtonUp {x, y, button, clicks}MouseWheel {x, y, direction}WindowShownWindowHiddenWindowExposedWindowMoved {x, y}WindowResized {width, height}WindowSizeChanged {width, height}WindowMinimizedWindowMaximizedWindowRestoredWindowEnterWindowLeaveWindowFocusGainedWindowFocusLostWindowCloseWindowDisplayChanged {display-index}DropFile {path}DropText {text}DropBeginDropCompleteOther {event-type}CursorKind
Stable cursor abstraction for UI runtimes.
Variants
ArrowIBeamWaitCrosshairWaitArrowSizeNWSESizeNESWSizeWESizeNSSizeAllNoHandaudio-s8
SDL constant audio-s8.
audio-u8
SDL constant audio-u8.
audio-s16lsb
SDL constant audio-s16lsb.
audio-s16msb
SDL constant audio-s16msb.
audio-s16sys
SDL constant audio-s16sys.
audio-u16lsb
SDL constant audio-u16lsb.
audio-u16msb
SDL constant audio-u16msb.
audio-s32lsb
SDL constant audio-s32lsb.
audio-s32msb
SDL constant audio-s32msb.
audio-f32lsb
SDL constant audio-f32lsb.
audio-f32msb
SDL constant audio-f32msb.
audio-status-stopped
SDL constant audio-status-stopped.
audio-status-playing
SDL constant audio-status-playing.
audio-status-paused
SDL constant audio-status-paused.
power-state-unknown
SDL constant power-state-unknown.
power-state-on-battery
SDL constant power-state-on-battery.
power-state-no-battery
SDL constant power-state-no-battery.
power-state-charging
SDL constant power-state-charging.
power-state-charged
SDL constant power-state-charged.
system-cursor-arrow
SDL constant system-cursor-arrow.
system-cursor-ibeam
SDL constant system-cursor-ibeam.
system-cursor-wait
SDL constant system-cursor-wait.
system-cursor-crosshair
SDL constant system-cursor-crosshair.
system-cursor-waitarrow
SDL constant system-cursor-waitarrow.
system-cursor-sizenwse
SDL constant system-cursor-sizenwse.
system-cursor-sizenesw
SDL constant system-cursor-sizenesw.
system-cursor-sizewe
SDL constant system-cursor-sizewe.
system-cursor-sizens
SDL constant system-cursor-sizens.
system-cursor-sizeall
SDL constant system-cursor-sizeall.
system-cursor-no
SDL constant system-cursor-no.
system-cursor-hand
SDL constant system-cursor-hand.
hat-centered
SDL constant hat-centered.
hat-up
SDL constant hat-up.
hat-right
SDL constant hat-right.
hat-down
SDL constant hat-down.
hat-left
SDL constant hat-left.
hat-rightup
SDL constant hat-rightup.
hat-rightdown
SDL constant hat-rightdown.
hat-leftup
SDL constant hat-leftup.
hat-leftdown
SDL constant hat-leftdown.
joystick-power-unknown
SDL constant joystick-power-unknown.
joystick-power-empty
SDL constant joystick-power-empty.
joystick-power-low
SDL constant joystick-power-low.
joystick-power-medium
SDL constant joystick-power-medium.
joystick-power-full
SDL constant joystick-power-full.
joystick-power-wired
SDL constant joystick-power-wired.
blendmode-none
SDL constant blendmode-none.
blendmode-blend
SDL constant blendmode-blend.
blendmode-add
SDL constant blendmode-add.
blendmode-mod
SDL constant blendmode-mod.
blendmode-mul
SDL constant blendmode-mul.
scalemode-nearest
SDL constant scalemode-nearest.
scalemode-linear
SDL constant scalemode-linear.
scalemode-best
SDL constant scalemode-best.
renderer-software
SDL constant renderer-software.
renderer-accelerated
SDL constant renderer-accelerated.
renderer-presentvsync
SDL constant renderer-presentvsync.
renderer-targettexture
SDL constant renderer-targettexture.
flash-cancel
SDL constant flash-cancel.
flash-briefly
SDL constant flash-briefly.
flash-until-focused
SDL constant flash-until-focused.
orientation-unknown
SDL constant orientation-unknown.
orientation-landscape
SDL constant orientation-landscape.
orientation-landscape-flipped
SDL constant orientation-landscape-flipped.
orientation-portrait
SDL constant orientation-portrait.
orientation-portrait-flipped
SDL constant orientation-portrait-flipped.
sensor-unknown
SDL constant sensor-unknown.
sensor-accel
SDL constant sensor-accel.
sensor-gyro
SDL constant sensor-gyro.
gl-red-size
SDL constant gl-red-size.
gl-green-size
SDL constant gl-green-size.
gl-blue-size
SDL constant gl-blue-size.
gl-alpha-size
SDL constant gl-alpha-size.
gl-buffer-size
SDL constant gl-buffer-size.
gl-doublebuffer
SDL constant gl-doublebuffer.
gl-depth-size
SDL constant gl-depth-size.
gl-stencil-size
SDL constant gl-stencil-size.
gl-accum-red-size
SDL constant gl-accum-red-size.
gl-accum-green-size
SDL constant gl-accum-green-size.
gl-accum-blue-size
SDL constant gl-accum-blue-size.
gl-accum-alpha-size
SDL constant gl-accum-alpha-size.
gl-stereo
SDL constant gl-stereo.
gl-multisamplebuffers
SDL constant gl-multisamplebuffers.
gl-multisamplesamples
SDL constant gl-multisamplesamples.
gl-accelerated-visual
SDL constant gl-accelerated-visual.
gl-context-major-version
SDL constant gl-context-major-version.
gl-context-minor-version
SDL constant gl-context-minor-version.
gl-context-profile-mask
SDL constant gl-context-profile-mask.
gl-share-with-current-context
SDL constant gl-share-with-current-context.
gl-framebuffer-srgb-capable
SDL constant gl-framebuffer-srgb-capable.
gl-context-release-behavior
SDL constant gl-context-release-behavior.
gl-context-profile-core
SDL constant gl-context-profile-core.
gl-context-profile-compatibility
SDL constant gl-context-profile-compatibility.
gl-context-profile-es
SDL constant gl-context-profile-es.
hint-default
SDL constant hint-default.
hint-normal
SDL constant hint-normal.
hint-override
SDL constant hint-override.
init
Initialize SDL with all subsystems (video, audio, timer, joystick, gamecontroller).
Returns:
Result Unit String
match init()
| Ok _ -> print "SDL initialized"
| Err err -> print "Failed: ${err}"
init-video
Initialize SDL video subsystem only.
Returns:
Result Unit String
match init-video()
| Ok _ -> print "Video initialized"
| Err err -> print "Failed: ${err}"
init-audio
Initialize SDL audio subsystem only.
Returns:
Result Unit String
match init-audio()
| Ok _ -> print "Audio initialized"
| Err err -> print "Failed: ${err}"
quit
Shut down SDL and clean up all subsystems.
Returns:
Unit
quit()
get-error
Get the last SDL error message.
Returns:
String
error = get-error()
print "SDL error: ${error}"
create-window
Create a window centered on screen with default flags.
Parameters:
Returns:
String -> Int -> Int -> Result {ptr: Ptr} String
match create-window "My Window" 800 600
| Ok window ->
# Use window...
destroy-window window
| Err err -> print "Failed: ${err}"
create-window-ex
Create a window with explicit position and flags.
Parameters:
Returns:
NonEmptyString -> Int -> Int -> PositiveInt -> PositiveInt -> Int -> Result {ptr: Ptr} String
flags = window-shown | window-resizable
match create-window-ex "My Window" 100 100 800 600 flags
| Ok window -> print "Window created"
| Err err -> print "Failed: ${err}"
destroy-window
Destroy a window and free its resources.
Parameters:
Returns:
{ptr: Ptr} -> Unit
destroy-window window
set-window-title
{ptr: Ptr} -> NonEmptyString -> Unit
get-window-title
{ptr: Ptr} -> String
set-window-size
{ptr: Ptr} -> PositiveInt -> PositiveInt -> Unit
get-window-width
{ptr: Ptr} -> Int
get-window-height
{ptr: Ptr} -> Int
window-size
Get the logical window size as a record.
{ptr: Ptr} -> {width: Int, height: Int}
set-window-position
{ptr: Ptr} -> Int -> Int -> Unit
get-window-x
{ptr: Ptr} -> Int
get-window-y
{ptr: Ptr} -> Int
window-position
Get the current window position as a record.
{ptr: Ptr} -> {x: Int, y: Int}
get-window-display-index
Get the display index currently hosting the window.
{ptr: Ptr} -> Int
get-native-window-info
Query platform-native window handles for renderer interop.
The first pass exposes the common desktop backends available from SDL_GetWindowWMInfo: Windows, X11, Cocoa, and Wayland.
{ptr: Ptr} -> Result NativeWindowInfo String
get-window-flags
Read the raw SDL window flags bitmask.
{ptr: Ptr} -> Int
has-window-flag?
Check whether a specific SDL window flag is present.
Int -> Int -> Bool
window-state-from-flags
Derive a normalized window-state record from raw SDL flags.
Int -> WindowState
window-state
Derive a normalized window-state record for a live window.
{ptr: Ptr} -> WindowState
is-window-hidden?
{ptr: Ptr} -> Bool
is-window-visible?
{ptr: Ptr} -> Bool
is-window-minimized?
{ptr: Ptr} -> Bool
is-window-maximized?
{ptr: Ptr} -> Bool
has-window-input-focus?
{ptr: Ptr} -> Bool
has-window-mouse-focus?
{ptr: Ptr} -> Bool
show-window
{ptr: Ptr} -> Unit
hide-window
{ptr: Ptr} -> Unit
raise-window
{ptr: Ptr} -> Unit
maximize-window
{ptr: Ptr} -> Unit
minimize-window
{ptr: Ptr} -> Unit
restore-window
{ptr: Ptr} -> Unit
set-fullscreen
{ptr: Ptr} -> Bool -> Unit
is-fullscreen?
{ptr: Ptr} -> Bool
create-renderer
Create a hardware-accelerated renderer for a window.
Parameters:
Returns:
{ptr: Ptr} -> Result {ptr: Ptr} String
match create-renderer window
| Ok renderer ->
# Use renderer...
destroy-renderer renderer
| Err err -> print "Failed: ${err}"
create-software-renderer
Create a software renderer for a window (slower, no hardware acceleration).
Parameters:
Returns:
{ptr: Ptr} -> Result {ptr: Ptr} String
match create-software-renderer window
| Ok renderer -> print "Software renderer created"
| Err err -> print "Failed: ${err}"
destroy-renderer
Destroy a renderer and free its resources.
Parameters:
Returns:
{ptr: Ptr} -> Unit
destroy-renderer renderer
clear
Clear the rendering target with the current draw color.
Parameters:
Returns:
{ptr: Ptr} -> Unit
set-draw-color renderer 0 0 0 255
clear renderer
present
Present the current rendering to the window (swap buffers).
Parameters:
Returns:
{ptr: Ptr} -> Unit
clear renderer
# Draw stuff...
present renderer
set-draw-color
Set the color used for drawing operations.
Parameters:
Returns:
{ptr: Ptr} -> Int -> Int -> Int -> Int -> Unit
set-draw-color renderer 255 0 0 255 # Red
draw-point
Draw a single point at the specified position.
Parameters:
Returns:
{ptr: Ptr} -> Int -> Int -> Unit
set-draw-color renderer 255 255 255 255
draw-point renderer 100 100
draw-line
Draw a line between two points.
Parameters:
Returns:
{ptr: Ptr} -> Int -> Int -> Int -> Int -> Unit
draw-line renderer 0 0 100 100
draw-rect
Draw a rectangle outline.
Parameters:
Returns:
{ptr: Ptr} -> Int -> Int -> Int -> Int -> Unit
draw-rect renderer 50 50 100 100
fill-rect
Draw a filled rectangle.
Parameters:
Returns:
{ptr: Ptr} -> Int -> Int -> Int -> Int -> Unit
set-draw-color renderer 0 255 0 255
fill-rect renderer 50 50 100 100
set-viewport
{ptr: Ptr} -> Int -> Int -> Int -> Int -> Unit
reset-viewport
{ptr: Ptr} -> Unit
load-texture
{ptr: Ptr} -> NonEmptyString -> Result {ptr: Ptr} String
destroy-texture
{ptr: Ptr} -> Unit
texture-width
{ptr: Ptr} -> Int
texture-height
{ptr: Ptr} -> Int
draw-texture
{ptr: Ptr} -> {ptr: Ptr} -> Int -> Int -> Unit
draw-texture-sized
{ptr: Ptr} -> {ptr: Ptr} -> Int -> Int -> Int -> Int -> Unit
draw-texture-ex
{ptr: Ptr} -> {ptr: Ptr} -> Int -> Int -> Int -> Int -> Float -> Bool -> Bool -> Unit
set-texture-alpha
{ptr: Ptr} -> Int -> Unit
set-texture-color
{ptr: Ptr} -> Int -> Int -> Int -> Unit
poll-event
Poll for pending events without blocking.
Returns:
Option RawEvent
match poll-event()
| Some event ->
if event.event-type == event-quit then
print "Quit requested"
else if event.event-type == event-keydown then
print "Key pressed: ${Int.to-string event.key-scancode}"
| None -> () # No events
wait-event
Wait indefinitely for an event (blocks until event arrives).
Returns:
Option RawEvent
match wait-event()
| Some event -> print "Got event: ${Int.to-string event.event-type}"
| None -> print "Error waiting for event"
wait-event-timeout
Wait for an event with timeout.
Parameters:
Returns:
NonNegativeInt -> Option RawEvent
match wait-event-timeout 1000
| Some event -> print "Got event within 1 second"
| None -> print "Timeout or no events"
event-from-raw
Normalize a raw SDL event record into a typed Event variant.
Common UI-relevant events are promoted to specific variants. Any event not yet normalized remains available as Other.
RawEvent -> Event
poll-event-typed
Poll for pending events without blocking and normalize them to typed variants.
Option Event
wait-event-typed
Wait indefinitely for an event and normalize it to a typed variant.
Option Event
wait-event-timeout-typed
Wait for an event with timeout and normalize it to a typed variant.
NonNegativeInt -> Option Event
is-key-pressed?
Int -> Bool
get-mod-state
Int
is-shift-pressed?
Bool
is-ctrl-pressed?
Bool
is-alt-pressed?
Bool
get-mouse-x
Int
get-mouse-y
Int
get-mouse-buttons
Int
is-mouse-button-pressed?
Int -> Bool
warp-mouse
{ptr: Ptr} -> Int -> Int -> Unit
set-relative-mouse-mode
Bool -> Unit
is-relative-mouse-mode?
Bool
show-cursor
Unit
hide-cursor
Unit
is-cursor-visible?
Bool
get-ticks
Get milliseconds since SDL initialization.
Returns:
Int
start = get-ticks()
# Do work...
elapsed = get-ticks() - start
print "Took ${Int.to-string elapsed}ms"
delay
Delay execution for specified milliseconds.
Parameters:
Returns:
Int -> Unit
print "Waiting..."
delay 1000 # Wait 1 second
print "Done!"
get-performance-counter
Get high-precision performance counter value.
Returns:
Int
start = get-performance-counter()
# Do work...
end = get-performance-counter()
freq = get-performance-frequency()
seconds = (end - start) / freq
get-performance-frequency
Get performance counter frequency (ticks per second).
Returns:
Int
freq = get-performance-frequency()
print "Timer frequency: ${Int.to-string freq} Hz"
get-clipboard-text
Option String
set-clipboard-text
String -> Unit
has-clipboard-text?
Bool
get-num-displays
Int
get-display-width
Int -> Int
get-display-height
Int -> Int
get-display-refresh-rate
Int -> Int
get-display-name
Int -> String
get-display-dpi
Get DPI metrics for a display as a record.
Int -> {diagonal: Float, horizontal: Float, vertical: Float}
show-info
NonEmptyString -> String -> Unit
show-warning
NonEmptyString -> String -> Unit
show-error
NonEmptyString -> String -> Unit
num-joysticks
Int
open-joystick
Int -> Result {ptr: Ptr} String
close-joystick
{ptr: Ptr} -> Unit
joystick-name
{ptr: Ptr} -> String
joystick-num-axes
{ptr: Ptr} -> Int
joystick-num-buttons
{ptr: Ptr} -> Int
joystick-get-axis
{ptr: Ptr} -> Int -> Int
is-joystick-button-pressed?
{ptr: Ptr} -> Int -> Bool
is-game-controller?
Int -> Bool
open-game-controller
Int -> Result {ptr: Ptr} String
close-game-controller
{ptr: Ptr} -> Unit
game-controller-name
{ptr: Ptr} -> String
game-controller-get-axis
{ptr: Ptr} -> Int -> Int
is-controller-button-pressed?
{ptr: Ptr} -> Int -> Bool
game-controller-update
Unit
game-controller-name-for-index
Int -> String
game-controller-is-attached?
{ptr: Ptr} -> Bool
game-controller-get-joystick
{ptr: Ptr} -> Result {ptr: Ptr} String
game-controller-get-type
{ptr: Ptr} -> Int
game-controller-has-axis?
{ptr: Ptr} -> Int -> Bool
game-controller-has-button?
{ptr: Ptr} -> Int -> Bool
game-controller-rumble
{ptr: Ptr} -> Int -> Int -> Int -> Unit
game-controller-has-rumble?
{ptr: Ptr} -> Bool
game-controller-set-led
{ptr: Ptr} -> Int -> Int -> Int -> Unit
game-controller-has-led?
{ptr: Ptr} -> Bool
get-version
{major: Int, minor: Int, patch: Int}
get-revision
String
get-platform
String
get-base-path
String
get-pref-path
String -> String -> String
prepare-macos-gui-app
Perform the package's macOS AppKit bootstrap path. This is a no-op on non-macOS platforms.
Unit
is-main-thread?
Returns true when the current call is running on the macOS process main thread. Always returns true on non-macOS platforms.
Bool
get-macos-screen-count
Returns the AppKit NSScreen.screens.count value on macOS. Returns -1 on non-macOS platforms or when AppKit screen enumeration is unavailable.
Int
get-core-graphics-display-count
Returns the CoreGraphics online display count on macOS. Returns -1 on non-macOS platforms or when display enumeration fails.
Int
get-num-video-drivers
Returns the number of compiled-in SDL video drivers.
Int
get-video-driver
Returns the SDL video driver name at the given index.
Int -> String
get-current-video-driver
Returns the currently active SDL video driver, or an empty string if video is not initialized.
String
init-video-driver
Initialize the SDL video subsystem using an explicit driver name.
String -> Result Unit String
video-quit
Shut down just the SDL video subsystem.
Unit
get-power-info
{state: Int, seconds: Int, percent: Int}
is-on-battery?
Bool
is-charging?
Bool
is-charged?
Bool
set-hint
NonEmptyString -> String -> Unit
get-hint
NonEmptyString -> String
is-hint-boolean?
NonEmptyString -> Bool -> Bool
clear-hints
Unit
get-num-audio-drivers
Int
get-audio-driver
Int -> String
get-current-audio-driver
String
get-num-audio-devices
Bool -> Int
get-audio-device-name
NonNegativeInt -> Bool -> String
open-audio-device
Int -> Int -> Int -> Int -> Result Int String
close-audio-device
Int -> Unit
pause-audio-device
Int -> Bool -> Unit
play-audio-device
Int -> Unit
get-audio-device-status
Int -> Int
is-audio-playing?
Int -> Bool
get-queued-audio-size
Int -> Int
clear-queued-audio
Int -> Unit
load-wav
NonEmptyString -> Result {buffer: Ptr, length: Int, freq: Int, format: Int, channels: Int} String
free-wav
Unit
num-haptics
Int
haptic-name
Int -> String
open-haptic
Int -> Result {ptr: Ptr} String
open-haptic-from-joystick
{ptr: Ptr} -> Result {ptr: Ptr} String
close-haptic
{ptr: Ptr} -> Unit
haptic-rumble-init
{ptr: Ptr} -> Unit
haptic-rumble-play
{ptr: Ptr} -> Float -> Int -> Unit
haptic-rumble-stop
{ptr: Ptr} -> Unit
is-haptic-rumble-supported?
{ptr: Ptr} -> Bool
haptic-set-gain
{ptr: Ptr} -> Int -> Unit
haptic-pause
{ptr: Ptr} -> Unit
haptic-unpause
{ptr: Ptr} -> Unit
haptic-stop-all
{ptr: Ptr} -> Unit
joystick-is-haptic?
{ptr: Ptr} -> Bool
mouse-is-haptic?
Bool
get-num-touch-devices
Int
get-touch-device
Int -> Int
get-touch-device-type
Int -> Int
get-num-touch-fingers
Int -> Int
get-touch-finger
Int -> Int -> {id: Int, x: Float, y: Float, pressure: Float}
num-sensors
Int
sensor-get-device-name
Int -> String
sensor-get-device-type
Int -> Int
open-sensor
Int -> Result {ptr: Ptr} String
close-sensor
{ptr: Ptr} -> Unit
sensor-get-name
{ptr: Ptr} -> String
sensor-get-type
{ptr: Ptr} -> Int
sensor-update
Unit
gl-set-attribute
Int -> Int -> Unit
gl-get-attribute
Int -> Int
gl-create-context
{ptr: Ptr} -> Result {ptr: Ptr} String
gl-delete-context
{ptr: Ptr} -> Unit
gl-make-current
{ptr: Ptr} -> {ptr: Ptr} -> Unit
gl-swap-window
{ptr: Ptr} -> Unit
gl-set-swap-interval
Int -> Unit
gl-get-swap-interval
Int
gl-extension-supported?
String -> Bool
gl-reset-attributes
Unit
gl-get-drawable-size
{ptr: Ptr} -> {width: Int, height: Int}
drawable-size
Get the drawable pixel size for the window.
The current implementation delegates to the existing GL-backed drawable size query exposed by SDL. This is useful as an immediate high-DPI helper while the package moves toward backend-neutral surface integration.
{ptr: Ptr} -> {width: Int, height: Int}
drawable-scale-from-sizes
Compute per-axis drawable scale factors from logical and drawable sizes.
{width: Int, height: Int} -> {width: Int, height: Int} -> {x: Float, y: Float}
drawable-scale
Compute the drawable scale factors for a window.
{ptr: Ptr} -> {x: Float, y: Float}
display-scale
Compute the effective display scale for a window.
This prefers the larger axis scale so slightly mismatched dimensions still produce a scale factor large enough for crisp rendering.
{ptr: Ptr} -> Float
start-text-input
Unit
stop-text-input
Unit
is-text-input-active?
Bool
set-text-input-rect
Int -> Int -> Int -> Int -> Unit
has-screen-keyboard-support?
Bool
is-screen-keyboard-shown?
{ptr: Ptr} -> Bool
system-cursor-type
Map a typed cursor kind to the SDL system cursor constant.
CursorKind -> Int
create-system-cursor
Int -> Result {ptr: Ptr} String
create-system-cursor-kind
Create a system cursor from the stable typed cursor kind.
CursorKind -> Result {ptr: Ptr} String
get-cursor
Unit -> {ptr: Ptr}
get-default-cursor
Unit -> {ptr: Ptr}
set-cursor
{ptr: Ptr} -> Unit
reset-cursor
Restore SDL's default cursor for the current window.
Unit
free-cursor
{ptr: Ptr} -> Unit
joystick-update
Unit
joystick-name-for-index
Int -> String
joystick-num-hats
{ptr: Ptr} -> Int
joystick-num-balls
{ptr: Ptr} -> Int
joystick-get-hat
{ptr: Ptr} -> Int -> Int
joystick-is-attached?
{ptr: Ptr} -> Bool
joystick-instance-id
{ptr: Ptr} -> Int
joystick-current-power-level
{ptr: Ptr} -> Int
joystick-rumble
{ptr: Ptr} -> Int -> Int -> Int -> Unit
joystick-has-rumble?
{ptr: Ptr} -> Bool
joystick-set-led
{ptr: Ptr} -> Int -> Int -> Int -> Unit
joystick-has-led?
{ptr: Ptr} -> Bool
joystick-get-type
{ptr: Ptr} -> Int