A collection of game development experiments using Raylib in Clojure. This project uses coffi for FFI bindings to call Raylib's C library directly from Clojure.
- JDK 22 or newer (required for the Foreign Function API)
- Leiningen (Clojure build tool)
Clojure runs on the JVM, so you need Java installed. This project requires JDK 22 or later because we use the new Foreign Function API to call native code.
On macOS with Homebrew:
brew install openjdk@22On Linux (Ubuntu/Debian):
sudo apt install openjdk-22-jdkAlternatively, you can use SDKMAN which works on macOS, Linux, and Windows (WSL):
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java 22.0.2-openLeiningen is the most common build tool for Clojure projects. It handles dependencies, runs your code, and manages the REPL.
On macOS with Homebrew:
brew install leiningenOn Linux, download the script directly:
curl -O https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
chmod +x lein
sudo mv lein /usr/local/bin/
lein # This will download the rest automaticallyOn Windows, download the installer from the Leiningen website or use Chocolatey:
choco install leinYou can verify everything is working by running:
lein versionClone this repository:
git clone https://github.com/yourusername/raylib-clojure-playground.git
cd raylib-clojure-playgroundRun one of the examples:
lein runIf you have multiple Java versions installed, you may need to set JAVA_HOME:
export JAVA_HOME=/path/to/jdk-22
lein runOn macOS, the path is usually something like:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-22.jdk/Contents/HomeClojure development is best experienced with a good editor that supports REPL integration. Here are two popular options.
Calva is a free extension that turns VS Code into a capable Clojure editor.
- Install VS Code
- Open the Extensions panel and search for "Calva"
- Install the Calva extension
- Open this project folder in VS Code
- Press Ctrl+Alt+C followed by Ctrl+Alt+J (or Cmd on macOS) to start a REPL
- Select "Leiningen" when prompted
Calva provides syntax highlighting, inline evaluation, and a connected REPL. You can evaluate code by placing your cursor on an expression and pressing Ctrl+Enter.
Cursive is a plugin for IntelliJ IDEA that provides excellent Clojure support. It requires a license for commercial use but is free for open source and personal projects.
- Install IntelliJ IDEA (Community or Ultimate edition)
- Go to Settings/Preferences and then Plugins
- Search for "Cursive" and install it
- Restart the IDE
- Open this project (File, Open, select the project folder)
- Cursive will detect the project.clj file and set everything up
To start a REPL in Cursive, right-click on project.clj and select "Run REPL for raylib-clojure-playground".
The main example runs Asteroids by default:
lein runTo run a specific example:
lein run -m examples.hello-world
lein run -m examples.pong
lein run -m examples.asteroids
lein run -m examples.tetrisOne of the best things about Clojure is the REPL workflow. You can change code while the game is running and see changes immediately.
Start a REPL:
lein replThen load and run an example:
(require '[examples.asteroids :as game])
(game/-main)- Hello World - A basic window with some text, good for testing your setup
- Pong - The classic two-player paddle game
- Asteroids - Shoot asteroids and try to survive
- Tetris - The block-stacking puzzle game
Most examples share these common controls:
- F1 toggles the debug overlay which shows FPS and memory usage
- Q or closing the window exits the game
- W and S move the left paddle
- K and J move the right paddle
- Enter starts the game
- Left and Right arrow keys rotate the ship
- Up arrow thrusts forward
- Space shoots or restarts after dying
This project includes pre-built Raylib libraries for different platforms in the libs folder:
| Platform | Directory | Library |
|---|---|---|
| macOS | libs/macos | libraylib.5.5.0.dylib |
| Linux 64-bit | libs/linux_amd64 | libraylib.so.5.5.0 |
| Linux 32-bit | libs/linux_i386 | libraylib.a |
| Windows 64-bit | libs/win64_msvc16 | raylib.dll |
| Windows 32-bit | libs/win32_msvc16 | raylib.dll |
The correct library is loaded automatically based on your operating system.
On macOS, you might see a security warning about the library. You can fix this by signing it locally:
codesign --force --sign - libs/macos/libraylib.5.5.0.dylibThis project uses coffi for calling native C code from Clojure. The newer versions of coffi require JDK 22 because that is when the Foreign Function and Memory API became stable (it was in preview in earlier versions).
OpenGL on macOS requires the main thread for rendering. The project.clj file includes the JVM flag -XstartOnFirstThread to handle this automatically.
EPL-2.0