0

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 glXCreateContextAttribsARB1. 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:

  1. The Linux is running in a VirtualBox VM. I have not tested a real distribution, but will do so presently.
  2. 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.

Community
  • 1
  • 1
geometrian
  • 14,775
  • 10
  • 56
  • 132
  • If you want to avoid implementing the indirection yourself and just do things on Windows as you can do on X11, you may want to have a look at this: https://github.com/datenwolf/wglarb – datenwolf Jan 24 '15 at 22:14
  • I am having exactly the same problem! I think it is a problem exclusive to the AMD fglrx graphics drivers, but Im not certain. I found if you preload the library with `LD_PRELOAD=/usr/lib64/fglrx/fglrx-libGL.so.1.2` before running the application then glGetString works fine, but that is a non-optimal solution and I really dont know how that causes it to work. Did you ever find a solution to your problem? – Ashley Sommer Jul 05 '15 at 02:21
  • @AshleySommer, no. The code that's in my codebase now reports a warning: _"This driver returned a null string for \"getGetString(0x1F02)\", signifying an error condition, and yet there actually isn't one. With no better information to go off of, libportcullis is going to ignore the lie and return a dummy string instead. This may cause inaccuracies later. This warning will occur once. See this file for more details."_ The file itself elaborates, and then points back to this question. – geometrian Jul 05 '15 at 06:51

1 Answers1

0

After creating the OpenGL context you have to make it current in the running thread and with a drawable. Use glXMakeCurrent or glXMakeContextCurrent.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Thanks, but I am already doing this in steps 2, 4, and 5. I have edited the question to list `glXMakeCurrent` explicitly. – geometrian Jan 24 '15 at 22:08