Skip to content

Add SDL2Swift wrappers for OpenGL, keyboard, mouse, and misc APIs#14

Merged
colemancda merged 12 commits into
masterfrom
feature/sdl2
Jul 8, 2026
Merged

Add SDL2Swift wrappers for OpenGL, keyboard, mouse, and misc APIs#14
colemancda merged 12 commits into
masterfrom
feature/sdl2

Conversation

@colemancda

Copy link
Copy Markdown
Member

Summary

Companion to #13 — adds the same surface area to SDL2Swift, adapted to SDL2's APIs (int/SDL_bool return codes instead of bool, device-index-based joystick enumeration, global relative-mouse-mode, no SDL_SyncWindow/SDL_GetCurrentTime/Properties API equivalents).

  • OpenGL.swift: GL context management (SDL_GL_CreateContext/MakeCurrent/DeleteContext/SwapWindow/attributes/swap interval), previously uncovered.
  • Keyboard.swift/Mouse.swift: polled input state (SDL_GetKeyboardState, SDL_GetMouseState, relative mouse mode, window mouse grab).
  • Time.swift, Log.swift, MessageBox.swift, Rect.swift, Joystick.swift.
  • Extends Gamepad.swift (name, rumble, player index, mapping files), Window.swift (fullscreen, position), VideoDisplay.swift (bounds, usable bounds, per-window display index, current video driver), and Event.swift (mouse wheel, text input, window close requested).

Not ported (no SDL2 equivalent): Properties.swift (SDL2 exposes SDL_GameControllerHasRumble directly, no general properties API), SDLWindow.sync() (no SDL_SyncWindow in SDL2), SDL.currentTime/SDLDateTime (no SDL_GetCurrentTime/SDL_time.h in SDL2).

Test plan

  • swift build (whole package) succeeds
  • swift test --filter SDL2Tests passes
  • Manual runtime smoke test: GL context creation/make-current/swap, keyboard state + scancode names, mouse state, ticks, logging, display bounds, video driver, window position/fullscreen, joystick enumeration all verified working against the local SDL2 install

colemancda added 12 commits July 7, 2026 19:56
Wraps SDL_GL_CreateContext/MakeCurrent/DeleteContext/SwapWindow and the
attribute get/set + swap interval APIs, which had no coverage before.
Wraps SDL_GetKeyboardState/SDL_GetScancodeName and adds ~50 named
Scancode constants for keybinding use cases.
Wraps SDL_GetMouseState/GetRelativeMouseState, SDL2's global relative-mouse-mode
setting, and per-window mouse grab.
Adds SDL_GameControllerName/HasRumble/Rumble/SetPlayerIndex, axis/button
string lookups, and the mapping-file/isGameController helpers.
Adds SDL_SetWindowFullscreen and SDL_GetWindowPosition. SDL2 has no
SDL_SyncWindow equivalent.
Needed as the return type for the new display bounds accessors.
Adds SDL_GetDisplayBounds/GetDisplayUsableBounds/GetWindowDisplayIndex and
SDL_GetCurrentVideoDriver.
Wraps SDL_GetTicks64/SDL_Delay, alongside SDL's existing reconstructed
nanosecond tick counter. SDL2 has no SDL_GetCurrentTime/DateTime API.
SDL's logging functions are C-variadic and unavailable in Swift, so this
routes through SDL_LogMessageV via withVaList with a fixed "%s" format.
Wraps SDL_ShowSimpleMessageBox.
Wraps SDL_NumJoysticks/SDL_JoystickGetDeviceInstanceID/SDL_JoystickNameForIndex,
distinct from the higher-level Gamepad API. SDL2 enumerates joysticks by
device index rather than returning an array of instance IDs like SDL3.
Adds SDL_MOUSEWHEEL, SDL_TEXTINPUT, and the SDL_WINDOWEVENT_CLOSE sub-event
cases, previously falling through to .unknown.
@colemancda colemancda merged commit 00c3f23 into master Jul 8, 2026
6 checks passed
@colemancda colemancda deleted the feature/sdl2 branch July 8, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant