I am calling glGetString(GL_VERSION)
to get the OpenGL version supported by the context I requested (I tried requesting GL 2 and GL 3 contexts, core and compatibility). However, it constantly returns null. This should be okay for all types of contexts (see e.g. the GL 4 docs). It also works fine on Windows.
In similar questions (e.g. foo, bar, baz, qux) I found, the problem was universally not setting a GL context first. To ensure that I do, I logged every relevant glX call to produce the following output:
1 Created basic context 0x17dd9d0 on display 0x17cdcb0.
2 Setting context 0x17dd9d0 onto window 77594626 on display 0x17cdcb0.
3 Created attribute context 0x1892e60 on display 0x17cdcb0.
4 Setting context (nil) onto window 0 on display 0x17cdcb0.
5 Setting context 0x1892e60 onto window 77594626 on display 0x17cdcb0.
Item 1 is glXCreateContext
. That context is set as current (glXMakeCurrent
) on a dummy window (item 2). Item 3 is using that context to create a context with glXCreateContextAttribsARB
1. Item 4 unsets the basic context (unnecessary) (glXMakeCurrent
again). Item 5 is setting the attribute context onto the window (glXMakeCurrent
again).
Immediately after this, glGetString
is called and returns null. According to the documentation, this means an error occurred. Checking with glGetError
produces, however, no error. If I don't get the string and just proceed to drawing, everything works great, showing that the attribute context is indeed set properly and legitimate.
The only factors I can think of that might be affecting this:
- The Linux is running in a VirtualBox VM. I have not tested a real distribution, but will do so presently.
- The window the context is set on is a dummy window that isn't displayed. It is however mapped/unmapped with
XMapWindow
/XUnmapWindow
so that the X server knows about it.
The question: what's going on?
1This indirection of creating a dummy context first to load the attribute context extension function is necessary on Windows. For code simplicity, I do the same procedure on Linux.