This repo contains an example of the simplest thing you can build opengl api (a beautiful triangle). It leverage the new FFM Api to call shared library of your OS, and jextract to generate java helpers. It uses the latest java LTS version, so you know this code is supported.
Good thing to know :
- The FFM API is stable, and you don't need to enable specific feature to use it.
- Since Java 17, the API has elvolved a bit, so care when you use AI, it can generate out-of-date code on this API.
- JDK 25
- Maven3
- Linux (only tested on this OS)
- OpenGL
- GLFW
- jextract (should be bundled in JDK25)
To check all these requirements
java --version
mvn --version
uname -r # Seriously ?
ldconfig -p | grep -E "glfw|libGL"
jextract --version
This is what I have on my system:
openjdk 25.0.1 2025-09-16
OpenJDK Runtime Environment (build 25.0.1)
OpenJDK 64-Bit Server VM (build 25.0.1, mixed mode, sharing)
Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b)
Maven home: /usr/share/java/maven
Java version: 25.0.1, vendor: Arch Linux, runtime: /usr/lib/jvm/java-25-openjdk # I use Arch btw
Default locale: fr_FR, platform encoding: UTF-8
OS name: "linux", version: "6.16.10-arch1-1", arch: "amd64", family: "unix"
6.16.10-arch1-1
libglfw.so.3 (libc6,x86-64) => /usr/lib/libglfw.so.3
libglfw.so (libc6,x86-64) => /usr/lib/libglfw.so
...
libGL.so.1 (libc6,x86-64) => /usr/lib/libGL.so.1
libGL.so.1 (libc6) => /usr/lib32/libGL.so.1
libGL.so (libc6,x86-64) => /usr/lib/libGL.so
libGL.so (libc6) => /usr/lib32/libGL.so
jextract 22
JDK version 22+35-2369
LibClang version clang version 13.0.0
I did some little OOP over some functions, and some are not discovered by the jextract toolkit, so in ShaderService
I had to manually link to existing functions (so you can see How you can do it yourself).
mvn compile
mvn exec:java
Annnnd voila !
(you can see my car in the background)