Hello,Robert. Thanks for your reversion.I'm so happy that I can add a new window in realtime.But there is a new problem :how to destroy the new window.I find that stopThreading can't destroy the window.Thanks. Waiting for you good news.
// // #include <osgDB/ReadFile> #include <osgUtil/Optimizer> #include <osgViewer/Viewer> #include <osgGA/MatrixManipulator> #include <osgGA/TrackballManipulator> #include <osgGA/StateSetManipulator> #include <iostream> #include <osg/Node> #include <osg/Geode> #include <osg/Geometry> #include <osgViewer/Viewer> class MyWindowHandler:public osgGA::GUIEventHandler { public: MyWindowHandler(): OneOrTwo(false) {} ~MyWindowHandler(){} bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa) ; switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { if(ea.getKey()==osgGA::GUIEventAdapter::KEY_F1) { OneOrTwo = !OneOrTwo ; viewer->stopThreading(); if(OneOrTwo) { int xoffset = 40; int yoffset = 40; viewer->stopThreading() ; viewer->startThreading() ; //{ // osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; // traits->x = xoffset + 0; // traits->y = yoffset + 0; // traits->width = 600; // traits->height = 480; // traits->windowDecoration = true; // traits->doubleBuffer = true; // traits->sharedContext = 0; // osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); // osg::ref_ptr<osg::Camera> camera = new osg::Camera; // camera->setGraphicsContext(gc.get()); // camera->setViewport(new osg::Viewport(0,0, traits->width, traits->height)); // GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; // camera->setDrawBuffer(buffer); // camera->setReadBuffer(buffer); // viewer->addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd()); //} { osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; traits->x = xoffset + 600; traits->y = yoffset + 0; traits->width = 600; traits->height = 480; traits->windowDecoration = true; traits->doubleBuffer = true; traits->sharedContext = 0; osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera; camera->setGraphicsContext(gc.get()); camera->setViewport(new osg::Viewport(0,0, traits->width, traits->height)); GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; camera->setDrawBuffer(buffer); camera->setReadBuffer(buffer); viewer->addSlave(camera.get(), osg::Matrixd::translate(-1.0,0.0,0.0), osg::Matrixd()); } //viewer->setSceneData(osgDB::readNodeFile("cow.osg")); viewer->realize() ; } return true ; } return false ; } break ; default: return false ; } } public: bool OneOrTwo ; }; int main( int argc, char **argv ) { osg::ArgumentParser arguments(&argc,argv); osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osg"); if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; } osgViewer::Viewer viewer; int xoffset = 40; int yoffset = 40; //viewer.stopThreading() ; //viewer.startThreading() ; viewer.addEventHandler(new MyWindowHandler()) ; { osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; traits->x = xoffset + 0; traits->y = yoffset + 0; traits->width = 600; traits->height = 480; traits->windowDecoration = true; traits->doubleBuffer = true; traits->sharedContext = 0; osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera; camera->setGraphicsContext(gc.get()); camera->setViewport(new osg::Viewport(0,0, traits->width, traits->height)); GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; camera->setDrawBuffer(buffer); camera->setReadBuffer(buffer); viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd()); } viewer.setSceneData(loadedModel.get()); viewer.realize(); //} return viewer.run(); } > Hi GuiYe, >At present the addSlave doesn't automatically tell the viewer to >realize windows, reset up threading and rendering support, which is >why you code isn't working. >What you need to do in you event handling is to call >viewer.stopThreading() first, create you new window/associated >view/camera then realize the new window and then call startTheading(). >Robert.
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org