qt - GLEW 和 Qt5 重新定义标题

标签 qt opengl glew

所以,

将我们的项目升级到 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'

希望您能提供帮助!

最佳答案

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

关于qt - GLEW 和 Qt5 重新定义标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17123100/

相关文章:

c++ - 带线程的 Qt 信号槽

c++ - GL VBO 问题 : First and final strip of triangles not being displayed correctly

qt - 如何子类化 QGLWidget 以使用 glew?

opengl - 用VBO画线时,如何指定索引?

c++ - CMake find_package 与 GLEW

c++ - QT .UI 显示.GIF?

linux - Qt 造物主 : add Qt module to project

c++ - 在visual 2010上编译qt项目链接错误

opengl - 使用具有多个采样器制服的单个纹理图像单元

c++ - 在 OpenGL 中使用 SOIL 将纹理添加到三角形时出现问题