10

所以,

将我们的项目升级到 Qt5 后,我们遇到了 glew 的问题。该应用程序链接了一个需要 glew 才能工作的库,并且在非 Qt 应用程序中使用该库时可以正常工作。

现在虽然我们将库链接到一个 qt 应用程序并渲染到一个 glwidget 中。这曾经可以工作,但现在不行了。我们得到大量错误,主要是说“重新定义”某些东西。这里有一些例子:

 1>c:\glew-1.9.0\include\gl\glew.h(275): error C2371: 'GLdouble' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(71) : see declaration of 'GLdouble'
1>c:\glew-1.9.0\include\gl\glew.h(630): warning C4005: 'GL_DOUBLE' : macro redefinition
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(68) : see previous definition of 'GL_DOUBLE'
1>c:\glew-1.9.0\include\gl\glew.h(1655): error C2371: 'GLintptr' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(38) : see declaration of 'GLintptr'
1>c:\glew-1.9.0\include\gl\glew.h(1656): error C2371: 'GLsizeiptr' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(39) : see declaration of 'GLsizeiptr'
1>c:\glew-1.9.0\include\gl\glew.h(1707): warning C4005: 'GL_BLEND_EQUATION_RGB' : macro redefinition
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(96) : see previous definition of 'GL_BLEND_EQUATION_RGB'
1>c:\glew-1.9.0\include\gl\glew.h(11533): warning C4005: 'GL_COVERAGE_SAMPLES_NV' : macro redefinition

你明白了。无论如何,我怎样才能阻止 Qt 包括它的 gl 东西,所以 glew 可以自己工作?

正如你所看到的,gles 是一个问题,所以我被指示使用这个:

#define QT_NO_OPENGL_ES_2

但这根本没有效果。还有其他不引用这些文件的错误:

    1>c:\glew-1.9.0\include\gl\glew.h(275): error C2371: 'GLdouble' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(71) : see declaration of 'GLdouble'
1>c:\glew-1.9.0\include\gl\glew.h(630): warning C4005: 'GL_DOUBLE' : macro redefinition
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(68) : see previous definition of 'GL_DOUBLE'
1>c:\glew-1.9.0\include\gl\glew.h(1655): error C2371: 'GLintptr' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(38) : see declaration of 'GLintptr'
1>c:\glew-1.9.0\include\gl\glew.h(1656): error C2371: 'GLsizeiptr' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(39) : see declaration of 'GLsizeiptr'
1>c:\glew-1.9.0\include\gl\glew.h(1707): warning C4005: 'GL_BLEND_EQUATION_RGB' : macro redefinition
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(96) : see previous definition of 'GL_BLEND_EQUATION_RGB'
1>c:\glew-1.9.0\include\gl\glew.h(11533): warning C4005: 'GL_COVERAGE_SAMPLES_NV' : macro redefinition
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengles2ext.h(530) : see previous definition of 'GL_COVERAGE_SAMPLES_NV'

希望您能提供帮助!

4

2 回答 2

4

经过一天的折腾,我有一个解决方案!

为了跨平台,Qt 似乎将 OpenGLES 设置为比桌面 openGL 更高的优先级。

对此的解决方案是在构建-opengl desktop之前从源代码中使用设置来构建 Qt。像这样的东西:

configure -debug-and-release -opengl desktop

然后使用nmake构建,它工作正常!

于 2013-06-15T16:28:12.527 回答
4

我个人将 OpenGL 与 Qt 结合使用的方法是将所有 OpenGL 相关部分与 Qt 类实现分开。在 Qt 部分中,我只需通过使用标准类型的常规 C 或 C++ 接口调用框架中立编写的 OpenGL 代码。由于实际的 OpenGL 代码没有引用 Qt,因此它不必包含 Qt 标头,从而避免像您这样的问题。

于 2013-06-15T12:35:38.737 回答