Go to file
peterino2 acd3f608ca saving, using 3.2.28 stable 2026-01-26 23:43:32 -08:00
sdl3-zig saving, using 3.2.28 stable 2026-01-26 23:43:32 -08:00
src updated generated bindings and added gpu example 2026-01-26 22:37:07 -08:00
.gitignore sample with zig 3.4.0 castholm's repo 2026-01-26 21:49:47 -08:00
README.md updated generated bindings and added gpu example 2026-01-26 22:37:07 -08:00
build.zig updated generated bindings and added gpu example 2026-01-26 22:37:07 -08:00
build.zig.zon saving, using 3.2.28 stable 2026-01-26 23:43:32 -08:00

README.md

SDL3 Sample Project with Zig Bindings

A sample SDL3 application using Zig-native bindings instead of C imports.

Features

  • SDL3 window initialization and management
  • Zig-native API bindings vendored from sdl3bind
  • Event loop with keyboard input handling
  • Exits on pressing Escape key
  • Basic rendering with color clear
  • GPU-accelerated rendering sample

Samples

Main Sample (src/main.zig)

Basic SDL3 window with traditional renderer API:

zig build run

GPU Sample (src/gpu_sample.zig)

SDL3 GPU API sample that initializes a GPU device and clears the screen with a yellowish color:

zig build run-gpu

Note: The GPU sample requires SDL3 to be built with GPU backend support (Vulkan, Metal, or D3D12). If you see "No supported SDL_GPU backend found!", ensure you have the appropriate graphics drivers and SDL3 GPU support installed.

Structure

  • src/main.zig - Main application using Zig SDL3 bindings (traditional renderer)
  • src/gpu_sample.zig - GPU API sample with render pass clear
  • sdl3-zig/ - Vendored Zig bindings for SDL3
    • sdl3.zig - Main module that re-exports all SDL3 APIs
    • sdl3/ - Individual API modules (init, video, events, render, gpu, etc.)
    • sdl3/c.zig - C import wrapper for SDL3 headers

Dependencies

  • SDL3 (castholm's Zig port) - v0.4.0+3.4.0
  • SDL3 Zig bindings - official/release-3.4.0

Building

zig build

Running

# Run the main renderer sample
zig build run

# Run the GPU API sample
zig build run-gpu

Press Escape to exit the applications.

Notes

  • Uses Zig 0.15.2 API
  • The Zig bindings provide type-safe, Zig-friendly wrappers around SDL3's C API
  • Opaque pointer types require @ptrCast when crossing between binding and C types
  • All SDL3 functions are accessed through the sdl import (e.g., sdl.init_fn(), sdl.video.createWindow())
  • GPU sample uses SDL3's new GPU API for modern graphics rendering