LWJGL Workspace

Click to watch the corresponding video on YouTube.

By the end of this tutorial you will have learned how to set up the LWJGL workspace for compiling and running LWJGL programs.

Downloading the required files

Download the latest version of the LWJGL here and the latest version of the “slick_util” jar-file here. Extract the downloaded zip-file and put all the files and folders in one directory. To install Eclipse, download the “Classic” or “IDE for Java Developers” version here. Put the downloaded Eclipse folder in a directory to which you have read and write permissions (i.e. not in Program Files or Applications).

Creating a project in the LWJGL workspace

Click the Eclipse executable. Select a Workspace folder, in which all your Java projects will be stored. Go to the menu “File”, “New”, click on “Java Project” and enter a name for the LWJGL project. The project files will be stored in the previously specified workspace folder.

Adding the library files

Open the project directory containing the “src” and “bin” directories. Add a directory called “lib” containing two subsequent directories called “natives” and “jars”. The project directory should now contain the following folders.

- lib
- src
- bin
- lib/natives
- lib/jars

Move the “lwjgl.jar” and “lwjgl_util.jar” files from the extracted zip-file and the “slick_util.jar” file to the “lib/jars” directory. Move the native files applicable to the current Operating System found in the zip-file to the “lib/natives” directory.

This is how the project folder should look.

Linking the jar files and the natives

Open Eclipse. Go to the menu “File” and click “Refresh”. Right-click on the previously created Eclipse project and click on “Properties”. Go to “Java Build Path” and select the “Libraries” tab. Click “Add JARs…” and select the “slick_util.jar”, “lwjgl.jar”, and “lwjgl_util.jar files. Expand the lwjgl.jar list item and double-click “Native Library Folder Configuration”.  Write the name of your project followed by “/lib/natives” and click “OK”.

Project Properties

This is what the Java Build Path window in Eclipse should resemble. (The “slick_util” jar-file should also be there.)

Testing the configuration

To test if it actually works copy the following code into your project and run it. In the case of no exceptions and the display of a window, the configuration has been set up correctly.

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
 
/**
 * If this application shows a blank and responsive window
 * and doesn't throw any errors, you know you have installed lwjgl
 * correctly.
 * @author Oskar Veerhoek
 */
public class DisplayTest {
    public static void main(String[] args) {
        try {
            Display.setDisplayMode(new DisplayMode(640, 480));
            Display.setTitle("Episode 1 – Display Test");
            Display.create();
        } catch (LWJGLException e) {
            System.err.println("Display wasn't initialized correctly.");
            System.exit(1);
        }
 
        while (!Display.isCloseRequested()) {
            Display.update();
            Display.sync(60);
        }
 
        Display.destroy();
        System.exit(0);
    }
}

java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path

This exception is thrown when LWJGL cannot find the native files it needs. Perhaps the natives file path has been set up incorrectly or the native files for another Operating System were selected.

Conclusion

That concludes this tutorial. Should you have any questions or remarks, leave them in the comments.

32 thoughts on “LWJGL Workspace

  1. Josefina1992

    This article is on 11 spot in google’s search results, if you want more visitors, you should build
    more backlinks to your blog, there is one trick to get free, hidden backlinks from authority forums,
    search on youtube; how to get hidden backlinks from forums

    Reply
  2. Amanda

    I see many sites outrank your blog in google’s search results.
    You should build more contextual backlinks.

    These type of backlinks are the most powerful
    after all these google algorithm updates. I know writing content is hard work, but i know what can help you save a
    lot of time, search in google for:
    Vesitos’s Rewriter

    Reply
  3. Egordorichev

    Tanks for this tutorial! But i have some problems:


    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    Display cannot be resolved
    DisplayMode cannot be resolved to a type
    Display cannot be resolved
    Display cannot be resolved
    LWJGLException cannot be resolved to a type
    Display cannot be resolved
    Display cannot be resolved
    Display cannot be resolved
    Display cannot be resolved

    at DisplayTest.main(DisplayTest.java:14)

    Reply
    1. James Yeoman

      That will either be that you forgot to import the libraries or that you messed up on the linking of the libraries. Double check your linking. And make sure you have all the natives (and make sure they’re the right OS natives. If you use Linux natives with Windows, eclipse can’t process the .jar files.) in the correct folder.

      Reply
  4. Rafaela

    Hello admin, i found this post on 16 spot in google’s
    search results. I’m sure that your low rankings are caused by hi bounce
    rate. This is very important ranking factor. One of the biggest reason for
    high bounce rate is due to visitors hitting the back button. The higher your
    bounce rate the further down the search results your posts and pages will end up, so having reasonably low bounce rate is important for improving your rankings naturally.
    There is very useful wordpress plugin which can help you.
    Just search in google for:
    Seyiny’s Bounce Plugin

    Reply
  5. Corey

    I get the following error:

    Exception in thread "main" java.lang.ExceptionInInitializerError
    at croussin.lwjgl.helloworld.HelloWorld.main(HelloWorld.java:11)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
    at org.lwjgl.opengl.LinuxDisplay.getAvailableDisplayModes(LinuxDisplay.java:951)
    at org.lwjgl.opengl.LinuxDisplay.init(LinuxDisplay.java:738)
    at org.lwjgl.opengl.Display.(Display.java:138)
    ... 1 more

    I can’t seem to figure out why its crashing on checking display modes. I run Arch Linux 64-bit, using Eclipse for my IDE and I’m using open-source graphics drivers (i.e. xf86-video-ati package)

    Reply
  6. Elioth Garcia

    im realy stressed i cant run it, Display wasn’t initialized correctly.
    is the only thing that apear me in console

    Reply
  7. Thijs

    Exception in thread “main” java.lang.UnsatisfiedLinkError: org.lwjgl.DefaultSysImplementation.getPointerSize()I
    at org.lwjgl.DefaultSysImplementation.getPointerSize(Native Method)
    at org.lwjgl.Sys.(Sys.java:113)
    at org.lwjgl.opengl.Display.(Display.java:132)
    at development.DisplayTest.main(DisplayTest.java:16)

    Got the references to lib/jars.
    lwjgl.jar is linked to the natives in lib/natives (natives from all operating systems included. I run win32).
    It doesn’t seem to work and I got no clue what the problem might be, I can remember vaguely having this problem before when I tried getting into LWJGL, but I can’t remember the solution. Any ideas?

    Reply
    1. Alex

      I had the same issue today when trying to run a Slick2D application. The issue came up, I think, because I used to different versions of LWJGL. Using Maven, Slick2D came with a dependency to LWJGL 2.9.1 while the natives I provided already came from 3.0. So I downloaded the 2.9.1 natives which solved the issue for me.

      Cheers,
      Alex

      Reply
  8. Jamie

    Hey, I set up lwjgl as you showed in the tutorial and pasted the code but when I run the program nothing happens. No errors/exceptions, no window pops up and the program just terminates. Any ideas?

    Thanks

    Reply
    1. Oskar Veerhoek Post author

      Are you sure you ran the file? Try putting a print statement in the code and see if it runs that.

      Reply
      1. Jamie

        Ah yeah, it doesn’t execute a print statement wherever I put it in the program. But I’m not sure why it isn’t running or how to fix it. Any ideas for this?

        Reply
          1. Jamie

            Ok, the program runs now but has the following error:
            Exception in thread “main” java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
            at java.lang.ClassLoader.loadLibrary(Unknown Source)
            at java.lang.Runtime.loadLibrary0(Unknown Source)
            at java.lang.System.loadLibrary(Unknown Source)
            at org.lwjgl.Sys$1.run(Sys.java:73)
            at java.security.AccessController.doPrivileged(Native Method)
            at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
            at org.lwjgl.Sys.loadLibrary(Sys.java:95)
            at org.lwjgl.Sys.(Sys.java:112)
            at org.lwjgl.opengl.Display.(Display.java:132)
            at Test.main(Test.java:14)

  9. Aritz

    It’s perfect. Short an well explained, not to get bored but to be easy to understand and follow.

    Continue like that.

    Reply

Leave a Reply to spuder Cancel reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>