Hot questions for Using Lightweight Java Game Library in eclipse

Question:

I am new with OpenGL. I have just installed LWJGL and created a User Library in Eclipse. It is linked to my Project but what Eclipse won't do is to import the needed classes automatically. Is there a way to get it work? I don't like to write (e.g.) GL30.glMethodName() every time and I also don't like to make a static import like import static org.lwjgl.opengl.GL30.* (which is bad practice).


Answer:

  1. Open the preferences window with Window -> Preferences.
  2. Go to Java -> Editor -> Content Assist -> Favorites.
  3. Click New Type....
  4. Enter org.lwjgl.opengl.GL11.
  5. Do steps 3 and 4 for each GL** class.
  6. When you now enter something like glGenVertexArrays(); and hover your mouse over it, there is an option Add static import for 'GL30.glGenVertexArrays'. Select it to add the import.
  7. Additionally, you can now type something like glGenVertex and press Ctrl+Space to get a popup menu of available methods. Selecting one of them automatically adds the import.

Question:

I know this has been answered before but none have worked. I tried to run a simple program,

enter code here
package tools.crystalcoffee.methods;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class DisplayMethod {
public void createDisplay(int width, int height) {
    try {
        //Here we set the size of the Display then create it
        Display.setDisplayMode(new DisplayMode(width,height));
        Display.create();
    } catch (LWJGLException e) {

        e.printStackTrace();
    }

    // init OpenGL here

    while (!Display.isCloseRequested()) {

        // render OpenGL here

        Display.update();
    }

    Display.destroy();
    }


public static void main(String[] argv) {
    //Make a debug thing
    Debug debug = new Debug();

    debug.debug("Works");

    //Making an instance?
    DisplayMethod displayExample = new DisplayMethod();

    //Starting
    displayExample.createDisplay(100,100);
}

}

But it always throws the same error, no matter if I add the native files or not.

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
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.<clinit>(Sys.java:112)
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at tools.crystalcoffee.methods.DisplayMethod.createDisplay(DisplayMethod.java:11)
at tools.crystalcoffee.methods.DisplayMethod.main(DisplayMethod.java:38)

I have looked everywhere for an answer, for 2 hours straight and thats ALL it throws. Help?


Answer:

Check your properties for lwjgl. I tried your program and first I got the same error (Unsatisfied link). Then if I make sure that all libraries are lwjgl 2.9.3 (get it from the legacy.lwjgl), then it works and the display starts rendering.

The exception we had seems to be becuase we had mixed versions of lwjgl 3 and 2.

See also LWJGL Display class can't be found

And Getting 'java.lang.UnsatisfiedLinkError': no lwjgl in java.library.path

Question:

I'm trying to work my way through ThinMatrix's Open Gl Java tutorial. And... I'm stuck on video 1. I also worked through the short precursor video where he installed on the dependencies (Including lwjgl 2) in eclipse. Right now I just have the very start of the first class:

package renderEngine;
import org.lwjgl.opengl.Display; //Error is here
import org.lwjgl.opengl.DisplayMode; //And here
//Handle the window
public class DisplayManager {
    //Create a display
    public static void createDisplay() {
        Display.setDisplayMode(new DisplayMode());
    }
}

I receive the error, "The import org cannot be resolved". Even though I've added the files to the build path config and I've added the native path in there as well. I've looked at this similar question and effectively tried every proposed solution. I've also tried deleting the project and reinstalling the dependencies. Here is my file tree for reference:

I'd be highly grateful if you could show me what I've done wrong. Thanks so much.

Edit 1:

I've discovered something interesting concerning the line:

Display.setDisplayMode(new DisplayMode());

While both Display and DisplayMode are underlined in red because the import is not working above, one of the "quick fixes" that comes up (even if I delete the import statements) is:

Import 'Display' (org.lwjgl.opengl)

Clicking this writes the import statement at the top (if it isn't there) or brings the cursor to it (if it is there). It then throws the aforementioned error. This seems to indicate that it does actually recognize the fact that the libraries are there, but for some reason can't import them.

The plot thickens.

Edit 2:

To check whether the problem is specifically to do with compatibility with lwjgl2 I've tried importing a class from another library (a linear algebra library called "jblas") with:

import org.jblas.Info;

...but once again I receive the same error. I guess this indicates that the problem is with the way that I am adding the scripts to the build path, with the software itself or a combination thereof.

To clarify how I put things on the build path:

Right click project name -> click "build path" -> click "configure build path" -> click "libraries" -> click on eiether "module path" or "class path" (I've tried both) -> click "add jars" -> navigate to my "lib" folder -> go inside "jars" folder -> select all the jars -> click "apply and close".

Edit 3:

I can import the built-in packages and I can import packages that I've made.


Answer:

EDIT: DON'T DO THE FOLLOWING: LOOK AT THE EDIT I downgraded my eclipse version to Oxygen, now I can import the packages without errors. Hopefully, this is remedied eventually so that I can move to the latest version of eclipse. Also, even in oxygen, it didn't work at first. I created a new project and reimported the various jars.

Edit: I faced this problem again, in oxygen

Fortunately this time I resolved it more quickly. I simply added the following snippet to my module-info.jar:

requires org.lwjgl;

Yep it was that simple.

was probably the problem the first time as well. This second problem arose from a second project I decided to make. The last project didn't have a module-info.jar.

That's why it allowed me to not write that line. Meanwhile, the original projects in eclipse 2018/19 did have the module-info.jar file and did have the problem. Maybe in Oxygen it just doesn't happen by default?

Question:

Originally I used:

public void DrawQuad(int x, int y, float width, float height) {
        GL11.glColor3f(0, 255, 255);

        glBegin(GL_QUADS); 

        glVertex2f(-x, y);
        glVertex2f(width, y);
        glVertex2f(width, -height);
        glVertex2f(-x, -height);

       glEnd();
}

But it just gives me this error:

A fatal error has been detected by the Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffd3538e18a, pid=2584, tid=0x0000000000000e38

JRE version: Java(TM) SE Runtime Environment (8.0_121-b13) (build 1.8.0_121-b13) Java VM: Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode windows-amd64 compressed oops) Problematic frame: C [lwjgl_opengl.dll+0xe18a]

Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

An error report file with more information is saved as: J:\SkiesDE\hs_err_pid2584.log

If you would like to submit a bug report, please visit: http://bugreport.java.com/bugreport/crash.jsp The crash happened outside the Java Virtual Machine in native code. See problematic frame for where to report the bug.

Code from runner class:

public static void run() {
        System.out.println("Hello LWJGL " + Version.getVersion() + "!");

        Display window1 = new Display(640, 480);
        window1.init();

        while(window1.isRunning()) {
            /*
            glBegin(GL_QUADS); 
            glVertex2f(-0.5f, 0.5f);
            glVertex2f(0.5f, 0.5f);
            glVertex2f(0.5f, -0.5f);
            glVertex2f(-0.5f, -0.5f);
            glEnd();
            */

            window1.DrawQuad(10, 10, 50, 50);

            window1.update(); 
        }

        window1.terminate();
    }



public static void main(String[] args) {
    run();
}

Code from Display Class:

public long window;
private int length;
private int heigth;

public Display(int length, int heigth) {
    this.length = length;
    this.heigth = heigth;
}

public void init() {
    if(!glfwInit()) {
        throw new IllegalStateException("Failed to initalize GLFW!");
    }

    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    window = glfwCreateWindow(length, heigth, "test", 0, 0); 
    //glfwGetPrimaryMonitor() Replace for full screen^
    if(window == 0) {
        throw new IllegalStateException("Failed to initalize Window!");
    }

    GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (videoMode.width() - length) / 2, (videoMode.height() - heigth) / 2);

    glfwShowWindow(window); 


}

public boolean isRunning() {
    return(!glfwWindowShouldClose(this.window));
}

public void update() {
    glfwSwapBuffers(window); 
    glfwPollEvents();
}

public void terminate() {
    glfwTerminate();
}

public void DrawQuad(int x, int y, float width, float height) {
    GL11.glColor3f(0, 255, 255);

    glBegin(GL_QUADS); 

    glVertex2f(-x, y);
    glVertex2f(width, y);
    glVertex2f(width, -height);
    glVertex2f(-x, -height);

    glEnd();
    //glLoadIdentity(); 
}

Answer:

You didn't bind the OpenGL Context to the window. You need to add glfwMakeContextCurrent(window) after window creation

Question:

I am following a tutorial on the basics of lwjgl. I am currently trying to make a simple window. However I am having two issues.

In my init() method I write

if(glfwInit() != GL_TRUE){
     throw new IllegalStateException("Unable to initialize GLFW");
}

and in my run() method I write

if(glfwWindowShouldClose(window) == GL_TRUE){
     running = false;
}

in both cases I get

Exception in thread "EndlessRunner" java.lang.Error: Unresolved compilation problem: 
The operator != is undefined for the argument type(s) boolean, int

at Main.init(Main.java:28)
at Main.run(Main.java:43)
at java.lang.Thread.run(Unknown Source)

However it seems that all tutorials use these lines in one way or another.


Answer:

The Java declartions of these methods are not quite the same as the C declarations so you need to adjust your code to match the Java declaration.

In both cases these methods return a boolean:

public static boolean glfwInit()

public static boolean glfwWindowShouldClose(long window)

so you use them using true and false rather than GL_TRUE and GL_FALSE:

if (glfwInit() != true) {

if (glfwWindowShouldClose(window) == true) {

Note: If Eclipse is showing there are errors in your code you will not be able to run it successfully.

Question:

I am trying to use DevIL but it keeps giving this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl-devil in java.library.path

when I run the line: IL.create();

I know that I need lwjgl-devil.dll. Where can I find it? I googled without success. I tried adding the lwjgl-devil.jar to Eclipse but that didn't work.


Answer:

You need the lwjgl-devil.dll and the DevIL.dll which you get here http://openil.sourceforge.net/download.php

Question:

Every time I look online the download is not in the same format as the current version, which leads to following the instructions and not being able to use the libraries I need. I'm new to lwjgl but fluent in java if someone could help me set up lwjgl I would be every appreciative. More specifically, the download is not broken up into folders like many that I see in tutorials.


Answer:

rightclick on Project > Properties > Java Build Path > add exterlnal jars...

Now navigate to the downloaded and extracted LWJGL-Folder and select all .jar files inside. And press Add and then Apply. Now it should work fine.

Question:

every time i try running my java project through eclipse (I use the lwjgl lib so i create a window) the window appears , freezes , then it's not responding it's not a code problem i tried a very basic code like

package data;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

import static org.lwjgl.opengl.GL11.*;
public class Boot {
    public Boot()
    {

        Display.setTitle("A.T's game");
        try {
            Display.setDisplayMode(new DisplayMode (640, 480));
            Display.create();
        } catch (LWJGLException e) {
            e.printStackTrace();
        }
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0,640,480,0,1,-1);
        glMatrixMode(GL_MODELVIEW);

        while(!Display.isCloseRequested())
        {
            glBegin(GL_LINES);
            glVertex2f(35,35);
            glVertex2f(53,53);
            glEnd();
        }
        Display.destroy();
    }
    public static void main(String[] args)
    {
        new Boot() ;
    }

}

Answer:

Your while loop is an infinite loop. You have to call Display.update() or it will not respond to any input, including the close request.

while (!Display.isCloseRequested()) {
    //...
    Display.update();
}