开发者

How to use GLEW with Qt?

开发者 https://www.devze.com 2023-01-26 03:04 出处:网络
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 refe

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 (n开发者_运维知识库ot 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 :)


You're not supposed to call glewInit() before you have your OpenGL context ready. Call it just before your first gl* calls, not at the beginning of main. That should do the trick.

Also, don't use glew32.lib and glew32s.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 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:

  1. Make new subclass of QGLWindget.
  2. In constructor of new class set up new QGLContext with proper OpenGL numbers.
  3. Call glewInit().
  4. Pass context to constructor QGLWidnet.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消