Skip to content
Heiko Brumme edited this page Nov 21, 2015 · 20 revisions

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

Downloading LWJGL3

  1. The very first step is of course downloading the library, you can get it here.
    This tutorial was made with LWJGL 3.0.0b.
  2. After that just extract the lwjgl.zip file to any location you want it to be.
  3. You should now have the folders doc, jar and native and a file src.zip.

Setting up your favorite IDE

Now that you have downloaded the library start up your IDE.

Note that you can also use an IDE independent approach by using Ant Ivy, Maven or Gradle to setup your application. Instructions for downloading LWJGL artifacts with Maven/Gradle/Ivy can be found in the LWJGL3 project repository.

For setting up with Ant Ivy you have to create a file called ivy.xml with following content:

<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
    <dependencies>
        <dependency org="org.lwjgl" name="lwjgl" rev="${lwjgl.version}"/>
        <dependency org="org.lwjgl" name="lwjgl-platform" rev="${lwjgl.version}">
            <artifact name="lwjgl-platform" m:classifier="natives-windows"/>
            <artifact name="lwjgl-platform" m:classifier="natives-osx"/>
            <artifact name="lwjgl-platform" m:classifier="natives-linux"/>
        </dependency>
    </dependencies>
</ivy-module>

With that you have to call ivy:retrieve in your Ant build.xml file, for that you have to add the attribute xmlns:ivy="antlib:org.apache.ivy.ant" in your project tag. You may also want to add <property name="lwjgl.version" value="3.0.0b"/> for defining the LWJGL3 version. After that you need to unpack the *.jar files which contain the native libraries.

If you want to use a snapshot build of LWJGL3 you can get it from the SonaType repository. For this you need a ivysettings.xml file with following content:

<ivysettings>
    <settings defaultResolver="sonatype"/>
    <property name="sonatype-snapshots" value="https://oss.sonatype.org/content/repositories/snapshots"/>
    <resolvers>
        <ibiblio name="sonatype" m2compatible="true" root="${sonatype-snapshots}"/>
    </resolvers>
</ivysettings>

With that you can change lwjgl.version to 3.0.0b-SNAPSHOT.

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 go into the folder where you extracted the lwjgl.zip and go into the jar folder and select lwjgl.jar
  6. At the Source tab click on Add JAR/Folder... and go into the folder where you extracted the lwjgl.zip and select src.zip
  7. At the Javadoc tab click on Add ZIP/Folder... and go once again in the folder where you extracted lwjgl.zip and go into the doc folder and select javadoc.zip

Now you can create a new project to test your setup. The following steps have to be done at 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. Of course select your LWJGL3 library
  4. Now right-click your project and click on Properties
  5. Go to the Run category
  6. Click into VM Options and type -Dorg.lwjgl.librarypath="<path to the extracted lwjgl.zip>/native with this LWJGL3 will choose the right native files for you, depending on your system.
    Note that you could also set it programmatically with System.setProperty("org.lwjgl.librarypath", "<path to the native folder>").

Eclipse

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 External Jars..., then go to your folder where you extracted lwjgl.zip and go in the jar folder and select lwjgl.jar
  6. Expand lwjgl.jar
  7. Select Source attachment and click on Edit...
  8. Click on *External File... and go to your folder where you extracted lwjgl.zip and select src.zip
  9. Select Javadoc location and click on Edit...
  10. Click on Browse... next to Archive path, go to your folder where you extracted lwjgl.zip and into the doc folder and select javadoc.zip
  11. Now in your main menu select Run -> Run Configurations...
  12. Select the Arguments tab
  13. Click into VM arguments and type -Dorg.lwjgl.librarypath="<path to the extracted lwjgl.zip>/native with this LWJGL3 will choose the right native files for you, depending on your system.
    Note that you could also set it programmatically with System.setProperty("org.lwjgl.librarypath", "<path to the native folder>").

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 Modules category
  4. Select the Dependencies tab
  5. Click on the green + -> Library... -> Java and choose your LWJGL3 global library, if you haven't made that before do the following steps
    1. Click on the green + -> Library... -> Java, then go to your folder where you extracted lwjgl.zip and go in the jar folder and select lwjgl.jar
    2. Click on the green +, then go to your folder where you extracted lwjgl.zip and select src.zip
    3. Click on the green +, then go again to the folder where you extracted lwjgl.zip and go into the doc folder and select javadoc.zip
    4. Set the Level to Global Library so you can add the library in a new project faster
  6. Now in your main menu select Run -> Edit Configurations
  7. Click on the green + and select Application
  8. Click into Main class and type the path to your main class
  9. Click into VM options and type -Dorg.lwjgl.librarypath="<path to the extracted lwjgl.zip>/native with this LWJGL3 will choose the right native files for you, depending on your system.
    Note that you could also set it programmatically with System.setProperty("org.lwjgl.librarypath", "<path to the native folder>").

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 get Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to load the native library: lwjgl you have not set the org.lwjgl.librarypath correctly. This is the most important part when setting up your project, so make sure you have set the native path to the right folder.

import org.lwjgl.Sys;

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.

Clone this wiki locally