OK, it seems that there is something odd in osg code.

As found in another topic views that uses the same graphic context don't need 
to be added to the compisite viewer at all but a simple instantiation make them 
appear on the composite viewer: that seems counterintuitive.
Moreover the compositeviewer example uses addView() even if the graphic context 
is the same for all viewes: so it seems the intent was to use addView to add a 
view not just create it!
The code of removeView() (and its counterpart addView()) behaves just like the 
view should be removed from the composite viewer but indeed it does not happen. 
I don't think the intent of a public API like addView/removeView was 
implemented with such a behavior in mind.

But there's something even more strange. If an added view is kept alive by a 
ref_ptr (see example below) the removeView() does not work as expected. On the 
contrary, removing comments from the following code, removeView works fine.

Gianni


Code:

#include <osgViewer/CompositeViewer>
#include <osg/GraphicsContext>

int main( int argc, char** argv )
{
    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
osg::GraphicsContext::Traits;
    traits->x = 100;
    traits->y = 100;
    traits->width = 500;
    traits->height = 300;
    traits->depth = 16;
    traits->windowDecoration = true;
    traits->supportsResize = true;
    traits->doubleBuffer = true;
    osg::ref_ptr<osg::GraphicsContext> graphicscontext = 
osg::GraphicsContext::createGraphicsContext(traits);

    osgViewer::CompositeViewer viewer;

    osgViewer::View * redView = new osgViewer::View();
    redView->setSceneData(new osg::Group);
    redView->getCamera()->setClearColor(osg::Vec4f(0.5,0,0,1));
    redView->getCamera()->setViewport(50, 50, 300, 100);
    redView->getCamera()->setGraphicsContext(graphicscontext);

    osg::ref_ptr<osgViewer::View> greenView = new osgViewer::View();
    //osgViewer::View * greenView = new osgViewer::View();
    greenView->setSceneData(new osg::Group);
    greenView->getCamera()->setClearColor(osg::Vec4f(0,0.5,0,1));
    greenView->getCamera()->setViewport(100, 100, 300, 100);
    greenView->getCamera()->setGraphicsContext(graphicscontext);

    viewer.addView(redView);
    viewer.addView(greenView);
    viewer.removeView(greenView);

    return viewer.run();
}




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=57547#57547





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to