[osg-users] Displaying a scene in the background of a QGraphicsView

Max Pfingsthorn max.pfingsthorn at gmail.com
Fri Sep 5 08:16:55 PDT 2008


Dear users,

this problem has been with me for a while. I've even tried it with other
graphics engines (Ogre) to no avail.

As shown in this toy project at Trolltech Labs

http://labs.trolltech.com/blogs/2008/06/27/accelerate-your-widgets-with-opengl/

I would like to show a scene in the background of a QGraphicsView and I
was very happy that the ViewerQT class already was a QGLWidget. However,
there seems to be something scaled wrong after I call viewer->frame().

Attached are a few screenshots and the code I have so far. I'm currently
running Ubuntu 8.04.1 and I'm using the OSG 2.2 binaries that came with
it. Beware that you need at least Qt 4.4 to compile this code.

qt-osg-1.png and -2.png show how far I am at the moment. Number 2 shows
the problem with scaling the window. OSG shows the scene fine in the
background, but the widget I'd like to overlay is stretched. I believe
the OpenGL version of QPainter draws in some normalized coordinates and
the bounding box isn't properly updated. qt-osg-ok-1.png and -2.png show
the same window sizes without calling viewer->frame(), and the scaling
of the widget is ok. Just no scene in the background of course.

I've traced the problem to osgViewer::Renderer::cull_draw(). I believe,
when the geometry of the view is set, something makes Qt stop drawing
correctly.

In the function which calls viewer->frame() (in
osgGraphicsView::drawBackground), I thought I save any sort of relevant
OpenGL state, the projection matrix, model/view matrix, and even the
texture matrix. After the call the viewer->frame(), I restore them
again. Is there any other state that I might have overlooked which is
set in the renderer? Also, do you have any idea why the Qt widget is not
drawn entirely sometimes? Could it have something do to with buffer swaps?

Thank you all for your help in advance!

Best regards,
Max Pfingsthorn
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt-osg-ok-2.png
Type: image/png
Size: 9701 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080905/8591986f/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: osgtest.zip
Type: application/zip
Size: 253214 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080905/8591986f/attachment-0002.zip>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt-osg-1.png
Type: image/png
Size: 12316 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080905/8591986f/attachment-0009.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt-osg-2.png
Type: image/png
Size: 11980 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080905/8591986f/attachment-0010.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt-osg-ok-1.png
Type: image/png
Size: 10367 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080905/8591986f/attachment-0011.png>


More information about the osg-users mailing list