sdl3-sample/README.md

69 lines
1.9 KiB
Markdown

# 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:
```bash
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:
```bash
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
```bash
zig build
```
## Running
```bash
# 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