[Qt-interest] [OT] Re: UpdateGL() not working from WheelEvent()

Till Oliver Knoll till.oliver.knoll at gmail.com
Fri Jun 10 08:50:23 CEST 2011



Am 10.06.2011 um 01:47 schrieb Jonathan Greig <redteam316 at gmail.com>:

> If you are missing makeCurrent() , that may be part of the problem as Till suggested.
> 
Yes, but only if your "entry point" into your GL code is any other than via the normal Qt event queue.

For instance if you react to a key press and want to change some GL state, toggling flat/smooth shading for instance, THEN you would have to call makeCurrent(), change the GL state, then call update() for a re-rendering.

However Qt makes sure that whenever one of your initializeGL/paintGL/resizeGL methods are called *from the Qt event loop* (and not "manually" from your own code) that the GL context is already made current - no need to call makeCurrent yourself.

In other words, the usual and easiest way to handle events:

- Handle the mouse/key/wheel/...
- Change your model, e.g. angle += 3.0
- Call update()

Update: I just checked the Qt docs on updateGL(), which calls glDraw:

"Executes the virtual function paintGL().
The widget's rendering context will become the current context and initializeGL() will be called if it hasn't already been called."
So it /should/ work as well! However it really means that control is not passed back to the event queue in between (which is why one would want to call updateGL in the first place, for performance reasons: you really want your scene re-rendered *now*).

However when you re-render your scene immediatelly(with updateGL) after every single (mouse) event and your system is flooded with such events, event queues might build up quickly, depending on the complexity of your scene! -> event handling will lag behind.

So better to call update() only within your event handlers. The Qt event queue will "merge" successive update calls (it merely "marks" the widget to be updated) and knows best when there is time to trigger a repaint.

If you think you know better then you problably want to use timers/threads and maybe even your own key/mouse system event handler (which would e.g.  discard or "sum up the net effect" of all events which had arrived while your app was busy re-rendering).

Also note that googling for "updateGL" showed similar discussions and problems, you might find your answer there as well, e.g.
  http://www.qtcentre.org/threads/2441-QGLWidget-updateGL()
When in doubt update to the latest Qt, try on a different platform and/or hardware, use the latest GL graphic card driver ;)

Cheers, Oliver
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110610/8cdd57b1/attachment.html 


More information about the Qt-interest-old mailing list