MCPcopy Index your code
hub / github.com/Zyko0/go-sdl3

github.com/Zyko0/go-sdl3 @v0.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.1 ↗ · + Follow
2,656 symbols 5,794 edges 171 files 1,550 documented · 58%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

go-sdl3

Go Reference Go Report Card

SDL3 bindings for Go in pure Go (thanks to ebitengine/purego).

About

This library wraps SDL3 packages to a more idiomatic go and: - Changes return values from bool to error. - Trims SDL_ prefix from all types, variables, function names. - Make methods from global functions when it is possible. - Turn some pointer function parameters into return values. - Remove the necessity to call sdl.Free on returned pointers.

If you are looking for pure Go bindings that are closer to the original API, please have a look at https://github.com/JupiterRider/purego-sdl3.

Status

[!NOTE] The list of currently implemented functions can be found in COVERAGE.md.

Libraries: - SDL3 (v3.4.0) - SDL3_ttf (v3.2.2) - SDL3_image (v3.2.6) - SDL3_mixer (v3.2.0) - SDL3_shadercross

Platforms: - Windows (amd64, arm64) - Linux (amd64) - MacOS (amd64, arm64) - WebAssembly (experimental)

Usage

The library is linked dynamically with purego (does not require CGo).

Embedded: The code below will write the library to a temporary folder, and remove it when the main function returns.

defer binsdl.Load().Unload()

Manual: If the library is installed or if the location is known (e.g: same folder), it can be loaded by its path.

sdl.LoadLibrary(sdl.Path()) // "SDL3.dll", "libSDL3.so.0", "libSDL3.dylib"

Example:

Note that you do not have to pass your update function to sdl.RunLoop, however doing so allows you to target GOOS=js/GOARCH=wasm, see wasmsdl.

package main

import (
    "github.com/Zyko0/go-sdl3/sdl"
    "github.com/Zyko0/go-sdl3/bin/binsdl"
)

func main() {
    defer binsdl.Load().Unload() // sdl.LoadLibrary(sdl.Path())
    defer sdl.Quit()

    if err := sdl.Init(sdl.INIT_VIDEO); err != nil {
        panic(err)
    }

    window, renderer, err := sdl.CreateWindowAndRenderer("Hello world", 500, 500, 0)
    if err != nil {
        panic(err)
    }
    defer renderer.Destroy()
    defer window.Destroy()

    renderer.SetDrawColor(255, 255, 255, 255)

    sdl.RunLoop(func() error {
        var event sdl.Event

        for sdl.PollEvent(&event) {
            if event.Type == sdl.EVENT_QUIT {
                return sdl.EndLoop
            }
        }

        renderer.DebugText(50, 50, "Hello world")
        renderer.Present()

        return nil
    })
}

Examples

The examples folder contains: - Some official examples (https://examples.libsdl.org/SDL3) - examples/renderer - examples/input - GPU API examples (https://github.com/TheSpydog/SDL_gpu_examples) - examples/gpu thanks to @makinori #21

External examples: - Clay UI renderer: TotallyGamerJet/clay/examples/sdl3 - Masterplan: SolarLune/masterplan

Extension points exported contracts — how you extend this code

ExampleInterface (Interface)
(no doc) [32 implementers]
examples/gpu/main.go
Numeric (Interface)
(no doc)
internal/memory_js.go

Core symbols most depended-on inside this repo

assert
called by 2219
cmd/wasmsdl/assets/sdl.js
makeInvalidEarlyAccess
called by 2133
cmd/wasmsdl/assets/sdl.js
createExportWrapper
called by 1886
cmd/wasmsdl/assets/sdl.js
GetJSPointer
called by 1178
internal/memory_js.go
Get
called by 1176
sdl/methods.go
StackAlloc
called by 1086
internal/memory_js.go
StackSave
called by 1052
internal/memory_js.go
StackRestore
called by 1052
internal/memory_js.go

Shape

Method 1,124
Function 1,083
Struct 279
TypeAlias 162
Class 6
Interface 2

Languages

Go76%
TypeScript24%

Modules by API surface

sdl/methods.go687 symbols
cmd/wasmsdl/assets/sdl.js633 symbols
sdl/functions.go202 symbols
sdl/sdl_structs.gen.go141 symbols
sdl/glue.go118 symbols
ttf/methods.go99 symbols
mixer/methods.go76 symbols
sdl/sdl_enums.gen.go71 symbols
img/functions.go58 symbols
sdl/sdl_types.gen.go30 symbols
internal/memory_js.go28 symbols
shadercross/types.go19 symbols

For agents

$ claude mcp add go-sdl3 \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page