[osg-users] [forum] add/remove nodes when rendering

Sophie Audonneau sophie.audonneau1 at etu.univ-lorraine.fr
Tue Apr 14 00:57:11 PDT 2015


I work on a project for witch I need to remove/add nodes while OpenSceneGraph is rendering.
I created a rendering window with OpenScenegraph and then I would like to be able to load/unload objects in it.
I make the calls for OSG frame() function inside a draw function and I use a singleton to manage the creation of the viewer. That way I managed to have a single viewer and then load my OpenSceneGraph objects inside that same viewer.
It seems fine but the problem is that I have to set camera and viewer parameters each time I call frame(). If I don't nothing is displayed, except OSG font colour. 
Ideally I would like to set the viewer parameters only when I load an OSG object for the first time.

Currently when I load an OSG object I use my singleton to find the viewer and to add the loaded node to the root associated to my viewer.
instance()->find_or_create_viewer(); //creates a viewer if none have been created yet
viewer_ = instance()->viewer(); // return a pointer to the unique osgViewer::Viewer

In my draw function I have to do the following :
viewer_->setUpViewerAsEmbeddedInWindow(viewParams[0],viewParams[1],viewParams[2] ,viewParams[3]);
viewer_->getCamera()->setProjectionMatrix( osg::Matrix(glMat_projection) );
viewer_->getCamera()->setViewMatrix( osg::Matrix(glMat_modelview) );

I have read that for dynamical rendering there was something to do about object's variance so I tried a few things but I didn't find how to solve my problem.

Thank you!


Read this topic online here:

More information about the osg-users mailing list