LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Twk Amz on April 07, 2015, 23:26:19

Title: Can't get lwjgl3 example code to work!
Post by: Twk Amz on April 07, 2015, 23:26:19
Hi, I'm trying to start using lwjgl but I'm having some troubles with the "installation". I am running on a 64bit Ubuntu 14.10 computer, I do all the setup process(you know, adding the jars, the natives, etc, etc) and I copy/paste the code from "Get Started" in the lwjgl website. But when I run it, there's no errors but the window doesn't show up.
I thought that maybe I was doing it wrong, but the same exact stapes on windows 64bit(yes, I'm adding the right natives) works just fine.

Also, I tried doing my own simple code to debug it and it seems that everything works up to "glfwCreateWindow()", if I try to write something with System.out.println before creating the window, the message is written, but if I add it afterwards, not. Just thinking that I had something to do with glfw or glfw bindings(I have glfw development libraries installed).

Any Ideas??
Title: Re: Can't get lwjgl3 example code to work!
Post by: abcdef on April 08, 2015, 08:29:49
Can you paste the full command you use to run the test app?
Title: Re: Can't get lwjgl3 example code to work!
Post by: Twk Amz on April 08, 2015, 21:14:08
Quote from: abcdef on April 08, 2015, 08:29:49
Can you paste the full command you use to run the test app?
I'm using eclipse. I am setting the natives, the jar and everrything. I'm 100% sure the error is not mine because the same setup runs on windows but not on linux
Title: Re: Can't get lwjgl3 example code to work!
Post by: Cornix on April 09, 2015, 07:25:47
QuoteI'm 100% sure the error is not mine because the same setup runs on windows but not on linux
That can have a multitude of reasons. Some graphics card drivers are more relaxed then others and just accept wrong arguments without complain while others are more strict. I had this once with 2 different video cards and the same code running on one but not on the other because of differences in the drivers GLSL compiler implementation.
Title: Re: Can't get lwjgl3 example code to work!
Post by: Twk Amz on April 11, 2015, 04:36:22
Quote from: Cornix on April 09, 2015, 07:25:47
QuoteI'm 100% sure the error is not mine because the same setup runs on windows but not on linux
That can have a multitude of reasons. Some graphics card drivers are more relaxed then others and just accept wrong arguments without complain while others are more strict. I had this once with 2 different video cards and the same code running on one but not on the other because of differences in the drivers GLSL compiler implementation.

But I tried with my own code and the get started example. My video card is a geforce gt730(i have nvidia drivers) ann the opengl version it supports is 4.4. I haven't had any problems with opengl so I think it has something to do with lwjgl.
Title: Re: Can't get lwjgl3 example code to work!
Post by: abcdef on April 11, 2015, 21:13:54
Highly unlikely lwjgl being the issue, I can run fine on linux (I use mint which is based on ubuntu) and I am sure there are quite a few others that do.
Title: Re: Can't get lwjgl3 example code to work!
Post by: Twk Amz on April 12, 2015, 17:45:05
Quote from: abcdef on April 11, 2015, 21:13:54
Highly unlikely lwjgl being the issue, I can run fine on linux (I use mint which is based on ubuntu) and I am sure there are quite a few others that do.
ok, but what can I do?? I mean, my computer supports opengl 4.4, I am setting up the workspace as shown here: https://www.youtube.com/watch?v=k6CcRi8yB5w (https://www.youtube.com/watch?v=k6CcRi8yB5w)(yes, I am using the linux natives), but the code won't work. The program starts and keeps running until I close the project from eclispe, but the window won't open.
Title: Re: Can't get lwjgl3 example code to work!
Post by: Kai on April 12, 2015, 18:37:22
This sounds like an issue with GLFW.
To verify that, you can build a minimal native GLFW application and see whether the issue is with that, too.
In order to do that, you can download the GLFW 3.1 sources (http://sourceforge.net/projects/glfw/files/glfw/3.1/glfw-3.1.tar.gz/download?use_mirror=switch), build GLFW as a static library (using CMake with GCC) and link your simple GLFW test application against that.
Using the C language, your simple GLFW application could look like so:

#include <GLFW/glfw3.h>
#include <stdio.h>
static void error_callback(int error, const char* description) {
fputs(description, stderr);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
int main(void) {
GLFWwindow* window;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
return 1;
window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
if (!window) {
glfwTerminate();
return 1;
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, key_callback);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}


I don't know how fit your are in building C programs, so I just name the required steps here:
First you install cmake by doing "apt-get install cmake".
Now you make sure you have gcc installed. If unsure, just "apt-get install gcc".
Next we need to make sure the OpenGL headers and RandR are installed with: "apt-get install xorg-dev libglu1-mesa-dev"
Once you extracted the sourceforge GLFW download, you create a new folder beneath "deps", "docs", "examples", etc. which you can name "build".
After that, you go into that "build" folder and execute "cmake .."
This will create a Makefile in that location which you can execute using "make".
Once that is done, there should be a libglfw3.a file somewhere there.

Now, you build the posted simple GLFW example code (assuming it is in a file called test.c) using:
gcc -Lglfw-3.1/build -lGL -lglfw3 -Iglfw-3.1/include -o test test.c

If you then run the created "test" application, it should show a window and should not hang in that "glfwCreateWindow" call. If it does, we have an issue with GLFW.
Title: Re: Can't get lwjgl3 example code to work!
Post by: Twk Amz on April 12, 2015, 18:43:31
well, I also thought about this, glfw is installed on my system(maybe lwjgl3 needs a specific version?), and I made a simple test in glfw, It worked, I tried to do the same on lwjgl but it didn't work.

Maybe this is not important, but instead of -lglfw3 I have to link against -lglfw
I have glfw3 installed, but the library is libglfw. Maybe that's the source of the problem?
Title: Re: Can't get lwjgl3 example code to work!
Post by: Kai on April 12, 2015, 18:56:19
LWJGL statically links against GLFW 3.1. So, it should not interfere with any glfw version in your system.
Did you attach a debugger to your Java process and indeed verified that it hangs in the native GLFW function and not somewhere in the Java code?
The next thing would be to attach a native debugger, such as GDB, to the java process with a debug build of lwjgl3 with a debug glfw variant.
Maybe Spasi can setup such a build for you.
Then we can see where in the native code the process hangs.

Regarding the glfw in your OS distribution's repository: Usually those are always a bit outdated, so please make sure to link against the GLFW 3.1 sourceforge download which you can build yourself with cmake, as shown above. When I do this for myself under Ubuntu I get a libglfw3.a in the build/src directory.
Title: Re: Can't get lwjgl3 example code to work!
Post by: Twk Amz on April 12, 2015, 19:26:02
Quote from: Kai on April 12, 2015, 18:56:19
Did you attach a debugger to your Java process and indeed verified that it hangs in the native GLFW function and not somewhere in the Java code?
How do I do this? You mean debugging "as java application"?
Title: Re: Can't get lwjgl3 example code to work!
Post by: Twk Amz on April 12, 2015, 20:47:34
I compiled and installed glfw3 from source and it doesn't work neither
Title: Re: Can't get lwjgl3 example code to work!
Post by: spasi on April 13, 2015, 06:43:36
This is a known issue (https://github.com/glfw/glfw/issues/368).
Title: Re: Can't get lwjgl3 example code to work!
Post by: Kai on April 13, 2015, 07:48:08
Spasi, could we not just use the latest GLFW git head, then?
From what I read, that issue is fixed regarding glfwCreateWindow (just not for glfwGetWindowFrameSize), so this would fix the issue, since no one invokes glfwGetWindowFrameSize for hidden windows.
Could you not create a build from it and try it out?
Title: Re: Can't get lwjgl3 example code to work!
Post by: spasi on April 13, 2015, 11:52:07
Yes, the LWJGL nightly always builds against the GLFW head. There was some trouble with the TeamCity server that I hadn't noticed, it's fixed now. Both the nightly and stable builds have been updated with the latest GLFW and LWJGL changes.
Title: Re: Can't get lwjgl3 example code to work!
Post by: Kai on April 13, 2015, 12:11:24
Cool. I just saw that the linux x64 build failed: https://travis-ci.org/LWJGL-CI/lwjgl3 (https://travis-ci.org/LWJGL-CI/lwjgl3)
Also the timestamp of the linux x64 liblwjgl.so from the nightly download zip has 08.04.2015 and not today.
Title: Re: Can't get lwjgl3 example code to work!
Post by: spasi on April 13, 2015, 16:46:25
Thanks, the travis workers come with Ant 1.8.4 and these (https://ant.apache.org/manual/ifunless.html) were failing silently. Fixed and uploaded a new build (#42).
Title: Re: Can't get lwjgl3 example code to work!
Post by: Twk Amz on April 13, 2015, 22:03:31
Quote from: spasi on April 13, 2015, 11:52:07
Yes, the LWJGL nightly always builds against the GLFW head. There was some trouble with the TeamCity server that I hadn't noticed, it's fixed now. Both the nightly and stable builds have been updated with the latest GLFW and LWJGL changes.
OMG, it worked. Thanks!