如何在 Qt 中使用 GLEW?
我想在 Windows 下将 GLEW 与 Qt 一起使用(7,如果有的话)。
我所做的就是访问 GLEW 网站,下载适用于 Windows 的软件包,然后将 glew.dll 放入 System32 文件夹中。在我的 pro 文件中,我使用 LIBS += .../path_to_the_libs/glew32.lib
引用了 .lib 文件,对于 glew32s.lib
也是如此(不确定什么是后者是为了)。在我的 QGLWidget 子类中,我确保 glew.h
包含在
之前,因此包含在 gl.h
和 之前glu.h
。在 main()
函数中,我做的第一件事是调用 glewInit
并调用 glGetError
但我的应用程序退出时出现一些奇怪的代码,就像一个非常奇怪的代码大负数。
我怀疑我可能做错了很多事情(我对 Qt 和 OpenGL 相对较新,对 GLEW 绝对陌生),但我也怀疑主要错误之一是我认为库是使用 MSVC 构建,因此无法与 MinGW 链接...无论如何,任何人都可以提供如何使用 Qt 安装 GLEW 并使用它的分步说明吗?我将非常感激。预先感谢您
编辑: 伙计们,也许我的要求太多了,但我真的很想要一步一步的指导:)
I want to use GLEW with Qt under Windows (7 if that matters).
What I did was go to the GLEW website, download the package for windows, then put the glew.dll in System32 folder. In my pro file, I referenced the .lib files with LIBS += .../path_to_the_libs/glew32.lib
and the same for glew32s.lib
(not sure what the latter's for). In my QGLWidget subclass, I made sure that glew.h
is included before <QGLWidget>
and therefore before gl.h
and glu.h
. In the main()
function the first thing I do is call glewInit
and call glGetError
but my application exits with some weird code, like a very large negative number.
I have a suspicion that there are very may thing I do wrong(I am relatively new to Qt and OpenGL and absolutely new to GLEW), but I also have a suspicion that one of the major errors is that the libs, I suppose, were built with MSVC and therefore cannot be linked against with MinGW... Anyway, can anyone please provide a step-by-step instruction how to install GLEW with Qt and use it? I would much appreciate it. Thank you in advance
Edit:
Guys, maybe I am asking for too much, but I would really really like a step-by-step instruction :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在准备好 OpenGL 上下文之前,您不应该调用
glewInit()
。在第一次gl*
调用之前调用它,而不是在main
的开头。那应该可以解决问题。另外,不要同时使用
glew32.lib
和glew32s.lib
- 前者与 DLL 文件一起使用,后者是静态的(你的 .exe 会变得更大)但您不必使用 .dll 来分发您的应用程序)。决定并使用其中之一。You're not supposed to call
glewInit()
before you have your OpenGL context ready. Call it just before your firstgl*
calls, not at the beginning ofmain
. That should do the trick.Also, don't use
glew32.lib
andglew32s.lib
simultaneously - the former is to use along with the DLL file and the latter is static (your .exe gets bigger but you don't have to distribute your application with the .dll). Decide and use either.Qt 4.7 可以创建任何 OpenGL 上下文。使用 QGLFormat.setProfile() 和 QGLFormat.setVersion()
唯一的缺点是您仍然没有 OpenGL 3+ 绑定。
逐步解决方案:
如果我没记错的话应该可以! GLEW dll 应放置在正确的系统文件夹中,并附加编译器选项,但它们与不带 QT 的 GLEW 相同。
Qt 4.7 can create any OpenGL Context. Use QGLFormat.setProfile() and QGLFormat.setVersion()
The only disadvantage is that you still do not have OpenGL 3+ bindings.
Step by step solution:
If I remember correctly it should do! GLEW dll should be placed in proper system folders, and compiler options attached, but they are the same as for GLEW without QT.