QOpenGLWidget与QApplication吗? [英] QOpenGLWidget with QApplication?

查看:188
本文介绍了QOpenGLWidget与QApplication吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个基于QWidget的应用程序,该应用程序以前使用QWindow进行OpenGL渲染.为了使该窗口适合我们的应用程序,我们必须使用

We have a QWidget based application that was previously using a QWindow for OpenGL rendering. To fit that window in our application we had to use

QWidget QWidget::createWindowContainer(QWindow);

以前,我们仅使用Qt OpenGL库外部进行渲染.

Previously we only used external to Qt OpenGL libraries for rendering.

我们希望从使用QWindow切换到某种类型的QWidget,以实现与触摸手势的兼容性,并且通常与我们的其他应用程序具有更好的整体兼容性.最新推荐的兼容OpenGL的QWidget似乎是QOpenGLWidget,因此我们尝试使用它.

We have a desire to switch from using QWindow to some kind of QWidget for compatibility with touch gestures, and generally better overall compatibility with the rest of our application. The latest recommended OpenGL compatible QWidget seems to be QOpenGLWidget, so we are trying to use that.

glContext是我们自己管理的OpenGLContext.

glContext is an OpenGLContext that we manage ourselves.

现在的问题是QOpenGLWidget不是QSurface,所以我无法调用

The problem now is that QOpenGLWidget is not a QSurface, so I cannot call

glContext->makeCurrent(this);

像以前使用自定义QWindow和我们自己的OpenGLContext一样,使上下文在我的自定义QOpenGLWidget上为当前状态.

to make the context current on my custom QOpenGLWidget like we could before with our custom QWindow and our own OpenGLContext.

如果我尝试使用QOpenGLWidget::makeCurrent();,那么它将使用错误的上下文,并尝试使用一些神奇的QT处理的上下文或我不理解的内容进行处理.

If I try to use QOpenGLWidget::makeCurrent(); then this uses the wrong context and tries to do stuff with some magical QT handled context or something I don't understand.

结果是,在我们尝试调用

The result is that after creating our OpenGLContext when we try to call

glFunctions = glContext->versionFunctions<QOpenGLFunctions_3_3_Core>();
if(!glFunctions->initializeOpenGLFunctions())
  printf("Could not initialize OpenGL functions.");

它总是无法初始化OpenGL函数.

It always fails to initialize the OpenGL functions.

我一直在阅读我可以在该主题上找到的所有其他资源,并遇到了类似的较早的Stack Overflow问题: 具有共享OpenGL上下文的QOpenGLWidget?

I have been reading over all the other resources I can find on the subject and came across this older Stack Overflow question that was similar: QOpenGLWidget with shared OpenGL context?

该问题的答案不能解决我的问题,因为我们使用的是QApplication,而不是QGuiApplication,因为这是基于QWidget的应用程序. 永远不会调用QGuiApplicationPrivate::init(),并且QOpenGLContext::globalShareContext()会返回空指针,因为它尚未初始化.

The answer to that question did not solve my issue because we are using QApplication, not QGuiApplication as this is a QWidget based application. QGuiApplicationPrivate::init() is never called and the QOpenGLContext::globalShareContext() returns a null pointer since it is not initialized.

不幸的是,我迫不及待要调用QOpenGLWidget::initializeGL()来初始化QT管理的OpenGLContext,因为我们已经在试图进行初始化的各种类上拥有大量的OpenGL资源.

Unfortunately I cannot wait for QOpenGLWidget::initializeGL() to be called to initialize the QT managed OpenGLContext since we already have lots of OpenGL resources over various classes that attempt to get initialized before that.

还有其他人遇到过同样的问题吗?

Has anyone else come across this same problem?

有什么建议吗?

推荐答案

我在这里做了一些猜测工作.

I am doing a little guess work here.

可能您的OpenGL默认为ANGLE. 您以前的应用程序OpenGL调用是特定于平台的OpenGL API.

Probably your OpenGL is defaulting to ANGLE. And your previous application OpenGL calls are platform specific OpenGL API.

尝试将以下属性设置为您的QApplication对象.

try setting below attribute to your QApplication object.

appObject->setAttribute(Qt::AA_UseDesktopOpenGL, true);

然后尝试致电

QOpenGLWidget::makeCurrent();

如果仍然无法正常工作,请为桌面OpenGL配置QT库.

If things are still not working, configure your QT libraries for desktop OpenGL.

configure -opengl desktop

以下链接为您提供了有关Qt OpenGL方法的一些信息. http://doc.qt.io/qt-5/windows-requirements. html

the below link gives you some information on Qt approach to OpenGL. http://doc.qt.io/qt-5/windows-requirements.html

输入注释(如果这对您没有帮助)将删除答案.

Put in comments, if this is not helping you, will delete the answer.

这篇关于QOpenGLWidget与QApplication吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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