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.

2008/6/7 GuiYe <[EMAIL PROTECTED]>:
>
>
> Hello,I want to add a new window in real time.But the below code doesn't
> work.Who can tell me why??I face it many days but...
>
> Waiting for your 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(true)
>    {}
>    ~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()==0xFF52)
>       {
>        OneOrTwo = !OneOrTwo;
>       }
>       if(OneOrTwo)
>       {
>        // right window + right slave camera
>         osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
> osg::GraphicsContext::Traits;
>         traits->x = 600;
>         traits->y = 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);
>         // add this slave camera to the viewer, with a shift right of the
> projection matrix
>         viewer->addSlave(camera.get(),
> osg::Matrixd::translate(-1.0,0.0,0.0), osg::Matrixd());
>         return true ;
>       }
>       return false ;
>      }
>      break ;
>     default:
>      return false ;
>     }
>    }
> public:
>  bool OneOrTwo ;
> };
> int main( int argc, char **argv )
> {
>  osg::ArgumentParser arguments(&argc,argv);
>  // read the scene from the list of file specified commandline args.
>  osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
>  // if not loaded assume no arguments passed in, try use default mode
> instead.
>  if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osg");
>  // if no model has been successfully loaded report failure.
>  if (!loadedModel)
>  {
>   std::cout << arguments.getApplicationName() <<": No data loaded" <<
> std::endl;
>   return 1;
>  }
>  // construct the viewer.
>  osgViewer::Viewer viewer;
>  int xoffset = 40;
>  int yoffset = 40;
>  // left window + left slave camera
>  {
>   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);
>   // add this slave camera to the viewer, with a shift left of the
> projection matrix
>   viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0),
> osg::Matrixd());
>  }
>  //// right window + right slave camera
>  //{
>  //    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);
>  //    // add this slave camera to the viewer, with a shift right of the
> projection matrix
>  //    viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,0.0,0.0),
> osg::Matrixd());
>  //}
>  osgUtil::Optimizer optimizer;
>  optimizer.optimize(loadedModel.get());
>  viewer.addEventHandler(new MyWindowHandler()) ;
>  // set the scene to render
>  viewer.setSceneData(loadedModel.get());
>  return viewer.run();
> }
>
>
> ________________________________
> 上房老大买二手房,看实景照片,挑专业经纪人
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to