【问题标题】:Qt5 and GLEW MX => glewInit failsQt5 和 GLEW MX => glewInit 失败
【发布时间】:2015-01-23 23:54:40
【问题描述】:

我们正在将我们的项目从 Qt 4.8 迁移到 5.4。我们在多个线程中使用多个上下文。为此,我们使用 GLEW MX(我们将所需的上下文设为当前上下文,然后在 GLEWContextStruct 的本地实例上调用 glewInit())。

我正在尝试将 QGLWidget 和 QGLContext 更改为 QOpenGLWidget 和 QOpenGLContext 但我最终无法再初始化 glew。 GLEW 不会返回错误,但 glGetError() 会。

我确实安装了带有 OpenGL 版本的 Qt 5.4 64。

这里是减少到最少的代码:

#include <QtWidgets/QApplication>

#define GLEW_MX
#define GLEW_STATIC
#include <GL/glew.h>

#include <qopenglcontext.h>
#include <qwindow.h>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    bool errQt;
    int errGlew;
    GLenum errorGL;

    QSurfaceFormat requestedFormat;
    requestedFormat.setVersion(3, 3);
    requestedFormat.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);

    //Creates the QGLWidget using the current context:
    QWindow window;
    window.setSurfaceType(QSurface::OpenGLSurface);
    window.setFormat(requestedFormat);
    window.create();

    //Create context
    QOpenGLContext context;
    context.setFormat(requestedFormat);
    errQt = context.create(); //true

    //Bind context
    context.makeCurrent(&window);

    //Glew context creation
    GLEWContext* pCtx = new GLEWContext; //All forwards undefined

    //Release context
    context.doneCurrent();

    return 1;
}

有什么建议吗? Qt5.4 可以使用 GLEW 吗?

编辑 1:

看来问题与 Qt 无关。创建的 GLEWContext 没有任何前向定义的函数(所有函数指针都未定义)。代码已更新,以帮助审阅者不会失去焦点。

【问题讨论】:

  • 哪个操作系统?显卡?司机? Qt用什么OpenGL选项编译?你的 glewInit 调用在哪里? (作为单独的消息,Qt 现在提供 GLEW 通过 QOpenGLContext::versionFunctions、QOpenGLExtensions 和各种 QOpenGL* 包装器提供的功能)

标签: multithreading opengl qt5 openglcontext


【解决方案1】:

我在项目中使用带有 Qt 5.4 的 glewInit(),但我使用 QWindow 作为我的基类,而不是 QOpenGLWidget。

在我的 ctor 中,我这样做:

QRiftWindow::QRiftWindow() {
 setSurfaceType(QSurface::OpenGLSurface);
 QSurfaceFormat format;
 format.setDepthBufferSize(16);
 format.setStencilBufferSize(8);
 format.setVersion(4, 3);
 format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
 setFormat(format);

 m_context = new QOpenGLContext;
 m_context->setFormat(format);
 m_context->create();
 ...

我在一个单独的线程上执行我的 OpenGL 工作。线程启动后,我会在我的类上调用 setup 方法

m_context->makeCurrent(this);
glewExperimental = true;
glewInit();
glGetError();

我之前使用 OpenGL 3.3 完成了完全相同的设置,没有任何问题。

【讨论】:

  • 我根据您的回答更新了我的代码,但最终遇到了同样的问题。如果我做错了什么或者您有任何其他建议,请告诉我。谢谢。
【解决方案2】:

你实际上应该得到一个警告:

#warning qopenglfunctions.h 与 GLEW 不兼容,GLEW 定义将是未定义的

#warning 要将 GLEW 与 Qt 一起使用,请不要在 glew.h 或之后包含或之后

您的“qopenglcontext.h”包括 .要回答您的问题,您可以使用 Qt + GLEW,但您不能轻易将 Qt-opengl 与 GLEW 混淆。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-04
    • 1970-01-01
    • 2013-06-11
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    相关资源
    最近更新 更多