2025-09-20 16:11:27 -07:00
|
|
|
# Lean SDL3 Bindings
|
|
|
|
|
|
2026-01-06 13:05:54 -08:00
|
|
|
This is my (Greg Shuflin's) fork of Srayan Jana's [Lean
|
|
|
|
|
SDL3](https://github.com/ValorZard/lean-sdl3) bindings. I've added a few
|
|
|
|
|
additional SDL3 bindings, particularly ones necessary to make the webcam work.
|
|
|
|
|
Note that this is an incomplete, work-in-progress project.
|
|
|
|
|
|
|
|
|
|
## Sample Projects
|
|
|
|
|
|
|
|
|
|
In this repo, run `just run` to build and run the original sdl3 demo, which
|
|
|
|
|
displays some basic graphics and plays an mp3. Run `just webcam` to build and
|
|
|
|
|
run the webcam demo, which accesses a webcam (if one exists) and mirrors its
|
|
|
|
|
video on the screen.
|
|
|
|
|
|
|
|
|
|
If you want to see an example project that uses these bindings, check this out:
|
|
|
|
|
|
|
|
|
|
https://github.com/ValorZard/lean-sdl-test
|
|
|
|
|
|
|
|
|
|
## How to use:
|
|
|
|
|
|
|
|
|
|
If you want to use SDL3 bindings in your own Lean4 project, add this library as
|
|
|
|
|
a dependency in your `lakefile.lean` (Not `.toml`)
|
2025-09-22 13:25:25 -07:00
|
|
|
|
|
|
|
|
In your default target in your project, make sure you do something like this
|
2025-09-20 16:11:27 -07:00
|
|
|
|
2025-09-22 13:25:02 -07:00
|
|
|
```lean
|
|
|
|
|
@[default_target]
|
|
|
|
|
lean_exe «lean-sdl-test» where
|
|
|
|
|
root := `Main
|
|
|
|
|
-- this is necessary because on Linux, binaries don't automatically get picked up by the executable unless you set the rpath
|
|
|
|
|
-- also, moreLinkArgs doesn't get inherited by the parent project
|
2026-09-08 15:23:49 -07:00
|
|
|
moreLinkArgs :=
|
|
|
|
|
if System.Platform.isWindows then #[]
|
|
|
|
|
else if System.Platform.isOSX then #["-Wl,-undefined,dynamic_lookup", "-Wl,-rpath,@executable_path"]
|
|
|
|
|
else #["-Wl,--allow-shlib-undefined", "-Wl,-rpath=$ORIGIN"]
|
2025-09-20 16:11:27 -07:00
|
|
|
```
|
2025-09-22 13:29:21 -07:00
|
|
|
|
2026-09-08 15:23:49 -07:00
|
|
|
On macOS, run the executable with `LEAN_MAIN_USE_THREAD=0`. Lean's runtime otherwise runs `main` on a
|
|
|
|
|
helper thread, and Cocoa refuses to create a video device off the main thread (`SDL_Init` fails with
|
|
|
|
|
"No available video device"). The `justfile` recipes set this for you.
|
|
|
|
|
|
2025-09-23 22:08:54 -07:00
|
|
|
|
2025-09-25 12:23:53 -07:00
|
|
|
## Acknowledgements
|
|
|
|
|
MASSIVE thanks to Oliver Dressler (@oOo0oOo) and Mac Malone (@tydeu) for all the help they gave!
|
|
|
|
|
|
2025-09-23 22:08:54 -07:00
|
|
|
## License & Attribution
|
|
|
|
|
|
2026-01-06 13:05:54 -08:00
|
|
|
MIT
|