Skip to content
Heiko Brumme edited this page Jan 3, 2018 · 20 revisions

This small guide is just to show you how to setup LWJGL3.

Downloading LWJGL3

Since version 3.1.0 LWJGL has a modular design for build artifacts. For convenience you can use the LWJGL build configurator. There you can choose if you want to download a ZIP Bundle or if you want to use a build tool. You could also browse through the artifacts at the bottom of the configurator and download each artifact manually.
This tutorial was made with the LWJGL release version 3.1.5 and the modules for GLFW, OpenGL and STB.

After downloading LWJGL as ZIP bundle or by using your build tool you will have multiple *.jar files. The lwjgl artifact is the core module, the binding artifacts have a lwjgl-<binding> naming scheme. Optionally you may also have differenct classifiers like sources for the source code, javadoc for the documentation or natives-<platform> for the native library files.

Setting up your favorite IDE

If you are using Maven, Gradle or Ant Ivy you can just copy the provided build script from the download tool in the specific build file of your project.

If you want to use the ZIP Bundle follow the following steps for your IDE.

NetBeans

You have to do the following steps just once.

  1. Go to Tools -> Libraries
  2. Click on New Library
  3. Type any name for the library like "LWJGL3"
  4. Select the newly made library
  5. At the Classpath tab click on Add JAR/Folder... and add all *.jar files from the place where you extracted the ZIP Bundle, without the artifacts with sources or javadoc in its name
  6. (Optional) At the Source tab click on Add JAR/Folder... and add all *-sources.jar files from the place where you extracted the ZIP Bundle
  7. (Optional) At the Javadoc tab click on Add ZIP/Folder... add all *-javadoc.jar files from the place where you extracted the ZIP Bundle

Now you can create a new project to test your setup. The following steps have to be done for each project.

  1. Create a new Java Application project via File -> New Project...
  2. In your project right-click on Libraries and select Add Library...
  3. Select your LWJGL3 library configured in the steps before
  4. Test your setup with the code below

Eclipse

You have to do the following steps just once.

  1. Go to Window -> Preferences
  2. Now choose Java -> Build Path -> User Libraries and click on New...
  3. Type any name for the library like "LWJGL3"
  4. Select the newly made library
  5. Click on Add external JARs... and add all *.jar files from the place where you extracted the ZIP Bundle, without the artifacts with sources or javadoc in its name
  6. (Optional) For each *.jar file (excluding the natives classified files) click on Source attachement -> Edit... and add the External location for the corresponding *-sources.jar file
  7. (Optional) For each *.jar file (excluding the natives classified files) click on Javadoc location -> Edit... and add the Javadoc in archive as External file for the corresponding *-javadoc.jar file

Now you can create a new project to test your setup. The following steps have to be done for each project.

  1. Create a new project via File -> New -> Java Project
  2. Right-click your project and select Properties
  3. Go into the Java Build Path category
  4. Select the Libraries tab
  5. Click on Add Library...
  6. Select User Library and check your LWJGL3 library configured in the steps before
  7. Test your setup with the code below

IntelliJ IDEA

The following steps have to be done for each project.

  1. Create a new Java project via File -> New Project
  2. In your main menu select File -> Project Structure
  3. Select the Libraries category
  4. Click on the green + -> Java
  5. Select the folder where you extracted the ZIP Bundle
  6. Confirm that the library will be added to your project
  7. Test your setup with the code below

Test your setup

After setting up your IDE just copy and paste this code, then run it. If it runs successfully then your setup is complete.
On Mac OS X you need to add -XstartOnFirstThread as JVM argument to start the application.
You may also need to add -Djava.awt.headless=true as JVM argument to get access to the AWT classes.

If you have added the natives to your classpath, the SharedLibraryLoader will extract them into a temporary folder and will set the org.lwjgl.librarypath accordingly.
Note that it is not recommended to rely on the SharedLibraryLoader. It is just there to have a simple setup by adding the natives to the classpath. In production you want to extract the native files yourself. For example by using a custom or platform-specific installer for your application which will extract the native files to a sub-directory of your application. In that case you need to set the VM option -Dorg.lwjgl.librarypath="<path to the native folder>". Alternatively you could also do it programmatically with System.setProperty("org.lwjgl.librarypath", "<path to the native folder>") or LWJGL's Configuration.LIBRARY_PATH.set("<path to the native folder>").

import org.lwjgl.Version;

public class TestSetup {

    public static void main(String[] args) {
        System.out.println("LWJGL Version " + Version.getVersion() + " is working.");
    }

}

After setting up the library and your IDE it is time to get started.

References

Appendix

Building from command line

Of course you could also compile your project from command line by calling javac -d <path to build directory> -cp <list of jar files> <list of source files> in the root directory.
For example in this project you would call javac -d build/ -cp "lib/*" src/silvertiger/tutorial/lwjgl/*.java src/silvertiger/tutorial/lwjgl/**/*.java for compiling.

After that you can run it with java -cp <path to the build folder>:<list of jar files> <main class>.
In the example project it is java -cp "build/:lib/*" silvertiger.tutorial.lwjgl.Main.