Hi all.

I am trying to get a WindowManager to work "ontop" of a CompositeViewer with all its views inside one window. I have managed to get it up and running but the widgets act wierd, I can turn them like if they were a node. Is there a way to achieve this or do i have to create a WindowManager for every view in the CompositeViwer and
how do i get widgets to move from a view to the other.
I found a similar question on http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2010-February/039025.html
but nobody seems to have any answers.

Regards Nikola R.


const unsigned int MASK_2D = 0xF0000000;
const unsigned int MASK_3D = 0x0F000000;

    osg::ref_ptr<osgViewer::CompositeViewer> compositeViewer =
            new osgViewer::CompositeViewer;

    osg::GraphicsContext::WindowingSystemInterface* wsi =
            osg::GraphicsContext::getWindowingSystemInterface();
    unsigned width, height;
    wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0),
                             width, height);

    osg::ref_ptr<osg::GraphicsContext::Traits> traits =
            new osg::GraphicsContext::Traits;

    traits->x = 200;
    traits->y = 200;
    width = width - 400;
    height = height - 400;
    traits->width = width;
    traits->height = height;
    traits->windowDecoration = true;
    traits->doubleBuffer = true;
    traits->sharedContext = 0;
    traits->overrideRedirect = true;

    osg::ref_ptr<osg::GraphicsContext> gc =
            osg::GraphicsContext::createGraphicsContext(traits.get());

    osgViewer::View* view0 = new osgViewer::View();
    osg::ref_ptr<osg::Camera> cam0 = view0->getCamera();
    cam0->setGraphicsContext(gc.get());
    cam0->setViewport(0, 0, width/2, height);
    cam0->setClearColor(osg::Vec4(0.5f, 0.6f, 0.5f, 1.0f));
    osg::Node* model0 = osgDB::readNodeFile("cessna.osg");
    model0->setNodeMask(MASK_3D);
    osg::Group* group0 = new osg::Group;
    group0->addChild(model0);
    view0->setSceneData(group0);
    view0->setName("view0");
    view0->setCameraManipulator(new osgGA::TrackballManipulator());
    compositeViewer->addView(view0);

    osgViewer::View* view1 = new osgViewer::View();
    osg::ref_ptr<osg::Camera> cam1 = view1->getCamera();
    cam1->setGraphicsContext(gc.get());
    cam1->setViewport(width/2, 0, width/2, height);
    cam1->setClearColor(osg::Vec4(0.5f, 0.5f, 0.6f, 1.0f));
    osg::Node* model1 = osgDB::readNodeFile("glider.osg");
    model1->setNodeMask(MASK_3D);
    osg::Group* group1 = new osg::Group;
    group1->addChild(model1);
    view1->setSceneData(group1);
    view1->setName("view1");
    view1->setCameraManipulator(new osgGA::TrackballManipulator());
    compositeViewer->addView(view1);


    osgViewer::View* view2 = new osgViewer::View();
    view2->setName("view2");

osgWidget::WindowManager* wm = new osgWidget::WindowManager(view2, width, height, MASK_2D); osgWidget::Window* box1 = new osgWidget::Box("HBOX", osgWidget::Box::HORIZONTAL);
    osgWidget::Label* label = new osgWidget::Label("label", "label");
    label->setSize(width, height);
    label->setColor(1.0f, 1.0f, 0.0f, 1.0f);
    box1->addWidget(label);
    box1->attachMoveCallback();
    box1->getBackground()->setColor(1.0f, 1.0f, 1.0f, 1.0f);
    wm->addChild(box1);
    wm->resizeAllWindows(true);

    osg::Group*  group2  = new osg::Group();
    osg::Camera* cam2 = wm->createParentOrthoCamera();
    view2->addEventHandler(new osgWidget::MouseHandler(wm));
    view2->addEventHandler(new osgWidget::KeyboardHandler(wm));
    view2->addEventHandler(new osgWidget::ResizeHandler(wm, cam2));
view2->addEventHandler(new osgWidget::CameraSwitchHandler(wm, cam1));
    view2->addEventHandler(new osgViewer::StatsHandler());
    view2->addEventHandler(new osgViewer::WindowSizeHandler());
    view2->addEventHandler(new osgGA::StateSetManipulator(
                               cam2->getOrCreateStateSet()
                           ));

    cam2->addChild(wm);
    cam2->setViewport(0, 0, width, height);
    cam2->setGraphicsContext(gc.get());
    view2->setCamera(cam2);
    compositeViewer->addView(view2);
    compositeViewer->run();

    return 0;

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to