简体   繁体   中英

Using glew with Qt 5.4 QOpenGLWidget

I am trying to use GLEW with the new QOpenGLWidget (that appeared in Qt 5.4). While I could do that quite easily with the older QGLWidget, it seems that the new QOpenGLWidget / QOpenGLContext classes do not collaborate well with GLEW (and I have no choice, I am using an external library that uses GLEW). I have the following problems:

  1. there is a compile-time warning (in qopenglfunctions.h triggered when GLEW_H is defined), and I cannot avoid including qopenglfunctions.h since it is included by QOpenGLContext
  2. (not sure it is related) in my application, I got an OpenGL stack underflow
  3. (not sure it is related) in my application, when I try making an OpenGL context current, it results in a black window for the whole application (I have several QOpenGLWidgets in the application, and need to change context because I am using OpenGL color clipping)

I would like to get rid of the warnings to determine whether 2. and 3. are related with GLEW/QOpenGLWidget incompatibility.

Note: There are already several questions about Qt5/GLEW on Stackoverflow, but they all relate with the (older) QGLWidget, that behaves quite differently (no problem with this one with the same code/application).

The codebase is located here: https://gforge.inria.fr/frs/?group_id=1465 (too large to be included here, and because of the length, I cannot ask you to take a look at it, just in case you want to know)

I was able to fix all the problems as follows (yes !):

  1. black window with makeCurrent(): I was trying to use QOpenGLContext::makeCurrent(Surface* ), it takes a Surface* as an argument, I did not have the right one. Now I am using QOpenGLWidget::makeCurrent() (that passes the right Surface* to the context);
  2. OpenGL stack matrix underflow error: this one was more tricky, this was because during my OpenGL rendering function, I was displaying some text in a QTextEdit widget the first time, this was causing something like an OpenGL context switch that was resetting the stack matrix. Fixed it by queing the updates for the text and treating them outside the OpenGL rendering function;
  3. Warnings due to Qt/glew.h: this one was easier, since I am no longer using QOpenGLContext (I am doing the context switch using QOpenGLWidget), I no longer need to include QtOpenGL header and have no longer any conflict.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM