-
Notifications
You must be signed in to change notification settings - Fork 65
Setup
This small guide is just to show you how to setup 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.
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.
You have to do the following steps just once.
- Go to Tools -> Libraries
- Click on New Library
- Type any name for the library like "LWJGL3"
- Select the newly made library
- 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 withsources
orjavadoc
in its name - (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 - (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.
- Create a new Java Application project via File -> New Project...
- In your project right-click on Libraries and select Add Library...
- Select your LWJGL3 library configured in the steps before
- Test your setup with the code below
You have to do the following steps just once.
- Go to Window -> Preferences
- Now choose Java -> Build Path -> User Libraries and click on New...
- Type any name for the library like "LWJGL3"
- Select the newly made library
- Click on Add external JARs... and add all
*.jar
files from the place where you extracted the ZIP Bundle, without the artifacts withsources
orjavadoc
in its name - (Optional) For each
*.jar
file (excluding thenatives
classified files) click on Source attachement -> Edit... and add the External location for the corresponding*-sources.jar
file - (Optional) For each
*.jar
file (excluding thenatives
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.
- Create a new project via File -> New -> Java Project
- Right-click your project and select Properties
- Go into the Java Build Path category
- Select the Libraries tab
- Click on Add Library...
- Select User Library and check your LWJGL3 library configured in the steps before
- Test your setup with the code below
The following steps have to be done for each project.
- Create a new Java project via File -> New Project
- In your main menu select File -> Project Structure
- Select the Libraries category
- Click on the green + -> Java
- Select the folder where you extracted the ZIP Bundle
- Confirm that the library will be added to your project
- Test your setup with the code below
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.
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
.
This tutorial and it's source code is licensed under the MIT license.
Written by Heiko Brumme, Copyright © 2014-2018