Help us shape the future of Go! Take the 2026 Go Developer Survey

go-sdl3

module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: MIT

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/dxui-org/go-sdl3/sdl"
	"github.com/dxui-org/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:

External examples:

Directories

Path Synopsis
bin
cmd
coverage command
docgen command
ffi2go command
jsgen command
methodgen command
wasmsdl command
examples
gpu command
helloworld command
puregoffi
Package puregoffi provides the small runtime support layer needed by the checked-in SDL bindings.
Package puregoffi provides the small runtime support layer needed by the checked-in SDL bindings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL