Hi,
I use OSG-3.2 along with Qt-5.2.
I want to embed an OSG scene in my Qt application.
I followed the osgViewerQt example, and I can get a working scene in my
application.
The problem I have is that the scene is updated with a timer, and I would like
it to be updated only when events are triggered, currently the events from the
camera manipulator, but later on other events
I set up the view in this way
Code:
view_ = new osgViewer::View;
addView( view_ );
osg::Camera* camera = view_->getCamera();
camera->setGraphicsContext( gw );
camera->setClearColor(osg::Vec4(0.2, 0.2, 0.6, 1.0));
camera->setViewport(new osg::Viewport(0, 0, w, h));
camera->setProjectionMatrixAsPerspective(30.0f,
static_cast<double>(w)/static_cast<double>(h), 1.0f, 10000.0f );
scene_->addChild(osgDB::readNodeFile("cessna.osg"));
view_->setSceneData(scene_.get());
view_->setCameraManipulator(new osgGA::TrackballManipulator);
setRunFrameScheme(osgViewer::ViewerBase::ON_DEMAND);
setThreadingModel(osgViewer::CompositeViewer::SingleThreaded);
With this code, the scene is displayed, but not updated with the manipulator
events.
I understand that the manipulator calls View::requestRedraw(), but this doesn't
seem to trigger an actual rendering. (ie QWidget::update() is not called)
I tried to add an Event Callback on the Camera, to catch the mouse events, and
to call the widget->update() method, but the callback gets called only when
actual rendering is performed, so I don't manage in this way.
The current fallback that I have is to install an event filter on the GLWidget:
Code:
bool SceneWgt::eventFilter(QObject *obj, QEvent *ev)
{
if (obj == glW_) {
switch(ev->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseMove:
update();
break;
default:
break;
}
}
return false;
}
This works, however the scene gets updated on each mouse move, even if there is
no change at all.
My questions:
1. Is it normal that View::requestRedraw() does not trigger rendering on Qt if
no timer is installed?
2. What would be the (or a) correct way to handle this problem?
IMHO the ideal would be to intercept View::requestRedraw() calls and to call
QWidget::update() (or CompositeViewer::frame() directly) from it.
3. Is there a mechanism to do this?
Thank you!
Cheers,
Remi
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=57925#57925
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org