在Linux上创建当前的OpenGL上下文 [英] Make current OpenGL context on Linux

查看:386
本文介绍了在Linux上创建当前的OpenGL上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上

HGLRC glContext       = wglGetCurrentContext();
HDC   deviceGLContext = wglGetCurrentDC();
wglMakeCurrent(glContext, deviceGLContext);

在Linux上,有类似的函数分别用于获取当前GL上下文和当前设备上下文,分别为glXGetCurrentContextglXGetCurrentDisplay.但我坚持

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 )

我不知道如何处理第二个参数.我将 Qt 用于GUI,但是我仍然需要几个Windows API函数,其中包括上面提到的三个.

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.

如何以帖子开头所述的相同方式进行调用glXMakeCurrent?问题是我不知道如何获取GLXDrawable.

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.

我需要获取一个GLXContext,然后创建另一个以共享Display列表,并使其在另一个线程中处于最新状态,然后将其添加到OpenCL上下文属性中.关键是我需要使它成为最新的.

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.

推荐答案

与Windows相反,在X11中,您正在处理客户端服务器模型. 显示"代表与X11服务器的连接. X11中有Drawable,它们可以互换使用. Windows是一种Drawable.

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.

您可能想看看 https://github.com/datenwolf/codesamples/tree/master/samples /OpenGL/x11argb_opengl 有关如何使用纯X11/GLX创建具有透明背景的OpenGL窗口的示例,可以在合成中使用.

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.

-

我需要获取一个GLXContext,然后创建另一个以共享Display列表,并使其在另一个线程中处于最新状态,然后将其添加到OpenCL上下文属性中.关键是我需要使它成为最新的.

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.

熟悉的问题.我对此的解决方案是将QGLWidget视为上下文.在您的另一个线程中,创建另一个QGLWidget,它将永远不会显示,并将可见的QGLWidget实例传递到构造函数的共享参数中.然后,您可以像使用上下文一样使用QGLWidget.这很脏,不是真的,但Qt的内部OpenGL系统就是这种方式.

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.

这篇关于在Linux上创建当前的OpenGL上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆