
LWJGL Template
๐ This is a template for kick-starting a LWJGL project
โ This template is using Java 1.11
๐ This is a Gradle project, it comes with the following dependencies:
guacamole: A small collection of some common and very basic utilities for libGDX games
For more details about dependencies, take a look at the build.gradle file
Getting started
Get this template by clicking on the
Use this template button at the top of this pageThis will generate a repository of your own with this template inside. After creating your brand new repository, go ahead and clone your repo:
Eg:
Choose a name for your project by changing the default name set inside settings.gradle:
Review and change any other configuration inside build.gradle if needed.
Build and run your appplication:
and voilร ! ๐จ
Breakdown
This repository is divided into the following:
Class with the main method:
GLFW windows may only be created on the main application thread. However, on MacOS systems, there's a strange behavior where this does not happen naturally and the following exception is thrown when trying to run the application.
More on that here.
As cited on the message above, a fix for that would be setting up the JVM flag
-XstartOnFirstThread. Even so, this is a manual process that needs to be done every time before the application is run on a MacOs system.
In order to avoid having to do anything outside of the application itself, a helper function startNewJvmIfRequired() is being used for this template, that will automatically start a new JVM with the necessary flag if the application was started on macOS without -XstartOnFirstThread.
This solution can be seen being used inside the main method inside Application.java (as shown on the snippet above) and was provided by the guacamole collection, thanks for that! ๐Color.java: Utilitary enum class for RGB colors. You can instantiate a Color with RGB values by its name.
For example, let's say you wanted to get the RGB values for the color
purple:The output would be:
Besides the already existing colors inside
Color.java, it's possible to modify it and add any additional colors as you desire.FileUtils.java: Utilitary class that can retrieve the contents of a resource file as an
InputStream.
For example, let's say you wanted to get the contents of a file whose path is {project_root}/src/main/resources/example/HelloWorld.txt.
The following code would print out the file contents of the file:NOTE: Files should be stored inside:
{project_root}/src/main/resources/ as this is the starting root directory for resources. Storing files inside this directory will ensure the files can also be located when you build your application into a jar.World.java: Configuration class that holds the values representing the projection of the world. The static funcion
setCoordinatePlane() will apply the configured values to the org.lwjgl.opengl.GL11.glOrtho() function.
For more details, take at look at the class itself.Window.java: Singleton class that holds the GLFW window configuration setup and the main game loop.
Usage:
Listeners: A Key Listener and a Window Resize Listener are configured for use with GLFW. Both are singletons.
Key Listener Example for quering if a key is pressed during the game loop:
Window Resize Listener: This listener will execute whatever is inside the method
reshape(long window, int width, int height); whenever GLFW detects that the window has been resized.Authors
License
This project is licensed under the MIT License - see the LICENSE file for details.
0 likes ยท 6 views ยท Jul 30, 2025
A well-organized LWJGL3 starter template using Java 11, Gradle, GLFW helper classes, and utility code