Skip to content

Demo suite for LWJGL 3, compiled to native image with GraalVM.

License

Notifications You must be signed in to change notification settings

chirontt/lwjgl3-demos

 
 

Repository files navigation

lwjgl3-demos + GraalVM native image

Demo suite for LWJGL 3, as described in the upstream repo with screenshots.


This fork provides build scripts to compile the project to native executable using the GraalVM native-image utility.

All demos in src are included in the build. Most demos are portable across different OSes, but some are GPU-specific, like the Vulkan demos which work only on discrete GPU with supporting Vulkan driver, or the CUDA demos which require a NVIDIA graphics card to run.

Gradle and Maven build scripts are provided for building the project, which requires JDK 11+ or GraalVM 21+ (for native image).

GraalVM pre-requisites

Setup for GraalVM native-image utility and C compiler

The GraalVM native-image page shows how to set up GraalVM and its native-image utility for common platforms. Gluon also provides some setup details for GraalVM native-image creation.

Native-image configuration files

The GraalVM native-image utility will use the configuration files in platform-specific folder to assist in the native-image generation.

The configuration files were generated when running the demos in standard JVM with a GraalVM agent, which tracks all usages of dynamic features of an execution of the demos and writes the info to the configuration files. Usage of the agent is contained in the Gradle build script (line 134), or in the Maven build script (line 171), which can be turned on (i.e. uncommented) and the demos are re-run to update the configuration files, if need be.

The above agent is not perfect; it sometimes misses some classes referenced via reflection which is used extensively in LWJGL. In the case of the LWJGL demos, many org.lwjgl.bgfx.* and org.lwjgl.assimp.* classes need be added manually to the configuration files, to avoid ClassNotFoundException being thrown when running the bgfx or assimp demos in the generated native image.

Gradle build tasks

Run in standard JVM

To build and run the demos in standard JVM with Gradle, execute the run task:

gradlew run

By default, the graphical demo launcher application is executed by the above run task without parameter. To run a specific demo, e.g. WavefrontObjDemo, execute the run task with that specific demo class as parameter:

gradlew run --args=opengl.assimp.WavefrontObjDemo

System properties can be passed on to the running demo with the -D parameter, e.g. to print out some debug info in the console:

gradlew run --args=opengl.assimp.WavefrontObjDemo -Dorg.lwjgl.util.Debug=true

The above tasks can use any standard JDK 11+.

Produce native executable

To generate native executable, GraalVM 22+ need be set up as mentioned in GraalVM pre-requisites section above.

Once GraalVM is set up and available in the path, run the nativeCompile task:

gradlew nativeCompile

The nativeCompile task would take a while to compile all demo source code and link them with the LWJGL libraries into an executable file. The resulting lwjgl3-demos file is (in Linux):

build/native-image-linux/lwjgl3-demos

(or if building on a Windows machine:

build\native-image-windows\lwjgl3-demos.exe

)

which can then be run to show the graphical demo launcher application:

./build/native-image-linux/lwjgl3-demos

Or to run a demo class directly as a parameter (e.g. DepthEdgeShaderDemo20):

./build/native-image-linux/lwjgl3-demos opengl.fbo.DepthEdgeShaderDemo20

Or to run a demo class directly with its own parameters (e.g. Bump):

./build/native-image-linux/lwjgl3-demos bgfx.Bump --gl --intel

System properties can be passed on to the running demo with the -D parameter, e.g. to print out some debug info in the console:

./build/native-image-linux/lwjgl3-demos opengl.fbo.DepthEdgeShaderDemo20 -Dorg.lwjgl.util.Debug=true

(or if building on a Windows machine:

build\native-image-windows\lwjgl3-demos.exe
build\native-image-windows\lwjgl3-demos.exe bgfx.Bump --gl --intel
build\native-image-windows\lwjgl3-demos.exe opengl.fbo.DepthEdgeShaderDemo20
build\native-image-windows\lwjgl3-demos.exe opengl.fbo.DepthEdgeShaderDemo20 -Dorg.lwjgl.util.Debug=true

)

Maven build tasks

Run in standard JVM

To build and run the demos in standard JVM with Maven, execute the compile then exec:exec tasks:

mvnw compile
mvnw exec:exec

By default, the graphical demo launcher application is executed by the above exec:exec task without parameter. To run a specific demo, e.g. WavefrontObjDemo, execute the exec:exec task with that specific demo class as value of the property class:

mvnw exec:exec -Dclass=opengl.assimp.WavefrontObjDemo

System properties can be passed on to the running demo with the -Dsys.props parameter, e.g. to print out some debug info in the console:

mvnw exec:exec -Dclass=opengl.assimp.WavefrontObjDemo -Dsys.props="-Dorg.lwjgl.util.Debug=true"

The above tasks can use any standard JDK 11+.

Produce native executable

To generate native executable, GraalVM 22+ need be set up as mentioned in GraalVM pre-requisites section above.

Once GraalVM is set up and available in the path, run the package task:

mvnw package

The package task would take a while to compile all demo source code and link them with the LWJGL libraries into an executable file. The resulting lwjgl3-demos file is (in Linux):

target/native-image-linux/lwjgl3-demos

(or if building on a Windows machine:

target\native-image-windows\lwjgl3-demos.exe

)

which can then be run to show the graphical demo launcher application:

./target/native-image-linux/lwjgl3-demos

Or to run a demo class directly as a parameter (e.g. Demo33Ubo):

./target/native-image-linux/lwjgl3-demos opengl.raytracing.Demo33Ubo

Or to run a demo class directly with its own parameters (e.g. Bump):

./target/native-image-linux/lwjgl3-demos bgfx.Bump --gl --intel

System properties can be passed on to the running demo with the -D parameter, e.g. to print out some debug info in the console:

./target/native-image-linux/lwjgl3-demos opengl.raytracing.Demo33Ubo -Dorg.lwjgl.util.Debug=true

(or if building on a Windows machine:

target\native-image-windows\lwjgl3-demos.exe
target\native-image-windows\lwjgl3-demos.exe bgfx.Bump --gl --intel
target\native-image-windows\lwjgl3-demos.exe opengl.raytracing.Demo33Ubo
target\native-image-windows\lwjgl3-demos.exe opengl.raytracing.Demo33Ubo -Dorg.lwjgl.util.Debug=true

)

About

Demo suite for LWJGL 3, compiled to native image with GraalVM.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 87.7%
  • GLSL 12.3%