A simple sample code from here. The code is running on ubuntu 14.04 64bit x86_64 platform. Problem: glfwInit() fails. The error callback function set by glfwSetErrorCallback was not called when glfwInit fails so I have no idea what happened. The GLFW version is 3.2.1 and the version string returned by glfwGetVersionString() is 3.2.1 X11 GLX EGL clock_gettime /dev/js Xf86vm
The linker option of the application is -pthread -ldl -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama -lX11 -lXcursor
Other compiling settings can be found in this thread: How to link GLFW?
I have no idea why GLFW is so hard to use. Could you please help me troubleshoot why the glfwInit() fails? If you need any information please let me know. Thanks a lot!
PS: if you happen to be working with GLFW on the same platform as mine, could you share your libglfw3.a file with me? Thanks.
I added checking code. It is a screenshot of the NetBeans IDE:
We can see that the execution flow enters line 100, indicating a failure of glfwInit(). The break point at line 75 in the error callback function was not caught at all.
I am now suspect if it is because the OpenGL version is not 4.5 as I expected. Typically, I check OpenGL version using GLEW_VERSION_4_5 in GLEW library, but how to do the same thing in GLFW? Does GLFW fail to work under OpenGL 1.2 which is the highest version of OpenGL that Windows can support?
You have error in your if statement - you wrote following code as two separate statements:
if (!glfwInit()); // <-- semicolon here means "if condition is true then do nothing"
exit(EXIT_FAILURE); // this executes always, regardless of previous line
Calling exit is not “under” if statement.
You want to code be like this:
if (!glfwInit()) // <-- note there's no semicolon here
As for OpenGL version - Windows supports up to latest OpenGL 4.5 version depending on your GPU card and installed GPU driver. glfwInit doesn’t care about OpenGL version, because it doesn’t touch OpenGL yet. When you create window only then OpenGL gets initialized. And if I’m not mistaken then by default it will try to create OpenGL context with version number as high as possible which your system supports.
But I’m not sure why you are worried about supported version of OpenGL on Windows if you are compiling and running code on Linux (Ubuntu).
@mmozeiko has the answer to your actual issue above (it’s not to do with your OpenGL version), however here’s some more information regarding cross platform OpenGL version support.
In order to get cross platform OpenGL support you need to use both GLFW for opening windows and getting events such as input, and an OpenGL function loader such as Glad, GLEW or gl3w. You’re using gl3w in your code. You can call:
int gl3wIsSupported(int major, int minor)
to find out if a version is supported using gl3w.
Depending on what graphics card and driver you have installed, gl3w should give you access to the core OpenGL functionality cross platform, including Windows.
Having tried the redbookexamples I note that there are some compile errors. I’ll try to reach Graham and see if he’s still maintaining the examples on Linux, but for now you might find it easier to take a look at the examples which come with GLFW such as https://github.com/glfw/glfw/blob/master/examples/simple.c
First, thank you all for helping me troubleshoot the issue.
Second, I apologize for the ; in if statement. It is painful to have to use both C++ and Python at the same time. I did stare at the ; but just didn’t notice the grammar error – you know what I mean.
Last but not least, after removing the ; and make sure glfwInit() successfully accomplished the initialization work, the program still fails to proceed. This time the error occurs at glfwCreateWindow and callback caught the error and printed it out. The error is:
Error: GLX: GLX version 1.3 is required
If you don’t believe, this is the screenshot:
From this, two conclusions can be drawn:
(1) Correct execution of GLFW DOES rely on OpenGL version. For some reason the OpenGL version of the running environment of my program is only 1.1 or 1.2, so GLFW fails.
(2) Windows DOES NOT support modern OpenGL interface. What one of the answerers claims is just a propaganda, but not truth.
So, the problem is essentially solved. But I know I leave a lot to say, so you can skip the following off-topic stuff if you are interested. To repeat, Windows DOES NOT support modern OpenGL interface. If you don’t believe, connect through Windows Remote Desktop to a remote machine (Linux or Windows, whatever) in which OpenGL 4.5 is indeed installed and show me inside the remote desktop what the version of OpenGL is. You’ll never got 4.5 because nVidia’s driver that supports OpenGL 4.5 is replaced with a generic VGA driver which only supports OpenGL 1.1 (or 1.2, I don’t remember distinctly). The pitfall I fell into is that I had thought it is only a problem due to Microsoft’s poor programming. It is true, however, also for StarNet X-Win32 with which I am using to connect to a linux machine from Windows. For the reason I explained above, Windows doesn’t support OpenGL 4.5, so programs in X-win32 can only run on OpenGL 1.1. Then, since GLFW can correctly run only on OpenGL 1.3 and above, as its error message says, the program fails. At last, if you ask: why didn’t you sit right in front of a linux machine and run the code directly? May I ask you back: it is weekend and it is raining hard outside, can I work at home on my Windows desktop? Someone says: “I was lazy”.
GLFW does not require any particular version of OpenGL.
GLX is a separate API from OpenGL and has its own version history. GLX is used to create OpenGL contexts on X Windows and yes, GLFW requires GLX version 1.3 or higher. If I recall correctly GLX 1.3 was released in 1998 and should be fairly widely available at this point, on the local machine.
However, it’s true that support in modern operating systems for remote OpenGL and associated APIs like GLX and WGL is very poor. It’s not prioritized anymore, partly because both the complexity of modern OpenGL and the amount of data typically required each frame has grown tremendously in the past decades. So the focus has shifted to rendering locally, and then sending only the final image. This is not something GLFW can affect.
Something like VNC may work better for your needs, depending on your remote machine.
I don’t quite understand why your conclusions about OpenGL support in Windows are based on code you are running under Linux. Those are two very different things.
And as @elmindreda is saying, GLX version is not the same as OpenGL version. You need to figure out why your Ubuntu is configured with less than GLX 1.3 verison. Have you have properly installed video drivers? Use glxinfo to determine what OpenGL version your Ubuntu supports. It’s again not a GLFW problem, you need to properly configure your OS.
Windows does support modern OpenGL through installable client drivers which you install with your graphics driver. However you are using StarNet X-Win32 which may only support a subset of OpenGL itself - i.e. one of your issues is with StarNet X-Win32’s OpenGL support. However your real problem appears to be with the version of GLX installed on your machine.
Local development of graphics code will be a lot easier for you, and if you need to work from your Windows PC I would recommend either developing on Windows with Visual Studio Community edition and cmake or installing Ubuntu on your local machine - you can even do this by just running a Live USB or CD install using something like LinuxLive USB or UNetbootin.