PDA

View Full Version : How to wait for a QGLWidget fully displayed before going on with the program?



dgray
23rd September 2008, 16:52
Hi folks,

a need some help with some QGL-stuff.
The background storry: I am trying to simulate a multi-camera-system with qt4 and opengl. Therefore I wrote a class GLCam derived from QGLWidget, which implements paintEvent() and does most of the GL-things (as suggested by Trolltechs tutorial http://doc.trolltech.com/4.4-snapshot/opengl-overpainting.html ).
This class holds a (simple) 3d-scene and each instance of GLCam represents a "virtual" camera looking at the scene from a different viewpoint, different technical parameters (resolution, sensor size, lens disturbance etc....). Now my application needs from each virtual camera an image. At the moment I do something like this to get the images



for(int i=0; i<numberOfCameras; ++i){
virtualCamera[i].raise();
virtualCamera[i].repaint();
virtualCamera[i].grabFrameBuffer().save( QString("image_%i.png").arg(i) );
}



This sequentially pops up all the "camera images" and saves them. It works for small "virtual" camera images (low resolution) quite well, but as I increase the resolution of the virtual cameras there is just some flicker and the images remain empty. I also tried activateWindow(), updateGL(), glFlush(), glFinish() in some places in the code, but it doesn't help at all:(
My guess is that grabFrameBuffer() doesn't wait till the painting is done. So no image can be obtained. Is there an easy way to wait until the widget is fully displayed? Something like virtualCamera[i].ensureVisibility()? Or a flag which indicates that the widget is fully visible?

Thanx in advance
DGray

jillian
3rd March 2010, 00:25
Maybe you're using double buffering and grabbing the wrong frame buffer. Qt documentation says to call glReadBuffer(...) prior to calling grabFrameBuffer, to ensure you are grabbing the correct buffer.

jillian
8th March 2010, 23:29
I just ran across the following special-purpose global function, while looking through the Qt documentation. Looks like it might do the trick, as far as waiting for the widget to fully display:

void qt_x11_wait_for_window_manager(QWidget* widget)

You can see this call being made prior to calling grabFrameBuffer on the widget, if you look at the code posted here:

http://qt.gitorious.org/qt/staging/blobs/619392c059326c11c24c1092ab62dd091114a0ab/tests/auto/qgl/tst_qgl.cpp