On Windows I do
HGLRC glContext = wglGetCurrentContext();
HDC deviceGLContext = wglGetCurrentDC();
wglMakeCurrent(glContext, deviceGLContext);
On Linux there are analogous functions for getting current GL context and current device context, glXGetCurrentContext
and glXGetCurrentDisplay
, respectively. But I am stuck with
Bool glXMakeCurrent( Display *dpy,
GLXDrawable drawable,
GLXContext ctx )
I don't know how to deal with the second parameter. I use Qt for GUI, but I still need several Windows API function, among which are the three ones mentioned above.
How to make the invoke glXMakeCurrent
in the same fashion described at the beginning of the post? The problem is that I don't know how to get GLXDrawable
.
I need to get a GLXContext, then create another one to share Display lists, and make it current in another thread, add it to OpenCL context attributes. The point is that I need to be able to make it current.
That 'GLXDrawable' is the X11 window for which you have got the context.
If you are using qt, I would have assumed it would have provided a 'myWindow.makeCurrent()' function, or something to the effect.
You can make a window using XCreateWindow
(there is also a function for making a basic window with less options). Before this, you will need to have got a connection to the display using XOpenDisplay
.
I have been very short on the details here, as there is a lot steps for getting an OpenGL Context in an X11 window, and whilst not hard, does involve a lot of error checking. I suggest you make use of a library that handles this for you.
Contrary to Windows, in X11 you are dealing with a client server model. The "display" represents the connection to the X11 server. In X11 there are Drawables, which can be used interchangably. One kind of Drawable are Windows.
You might want to have a look at
https://github.com/datenwolf/codesamples/tree/master/samples/OpenGL/x11argb_opengl
for an example on how to create OpenGL window with a transparent background using plain X11/GLX, that can be used in compositing.
--
Update
I need to get a GLXContext, then create another one to share Display lists, and make it current in another thread, add it to OpenCL context attributes. The point is that I need to be able to make it current.
Familiar problem. My solution to this is to treat a QGLWidget as if it was a context. In your other thread create another QGLWidget, that will never be shown and pass the visible QGLWidget instance into the sharing parameter of the constructor. Then you can use the QGLWidget as if it were a context. It's dirty, not really to the point, but Qt's internal OpenGL system is that way.