- Timestamp:
- 01/05/07 14:15:59 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osghangglide/osghangglide.cpp
r5890 r5901 115 115 osgViewer::Viewer viewer; 116 116 117 viewer.setCameraManipulator(new GliderManipulator());118 119 117 // if user request help write it out to cout. 120 118 if (arguments.read("-h") || arguments.read("--help")) … … 123 121 return 1; 124 122 } 123 124 bool customWindows = false; 125 while(arguments.read("-1")) customWindows = true; 126 while(arguments.read("-2")) customWindows = false; 125 127 126 // any option left unread are converted into errors to write out later. 127 arguments.reportRemainingOptionsAsUnrecognized(); 128 if (customWindows) 129 { 130 osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); 131 if (!wsi) 132 { 133 osg::notify(osg::NOTICE)<<"View::setUpViewAcrossAllScreens() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl; 134 return 0; 135 } 128 136 129 // report any errors if they have occured when parsing the program aguments. 130 if (arguments.errors()) 131 { 132 arguments.writeErrorMessages(std::cout); 133 return 1; 134 } 135 136 // load the nodes from the commandline arguments. 137 osg::Node* rootnode = osgDB::readNodeFiles(arguments); 138 if (!rootnode) rootnode = createModel(); 137 unsigned int width, height; 138 wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); 139 139 140 viewer.setSceneData( rootnode ); 140 width -= 500; 141 height -= 500; 141 142 142 #if 0 143 osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; 144 traits->x = 500; 145 traits->y = 500; 146 traits->width = width; 147 traits->height = height; 148 #if 0 149 traits->windowDecoration = false; 150 #else 151 traits->windowDecoration = true; 152 #endif 153 traits->doubleBuffer = true; 154 traits->sharedContext = 0; 143 155 144 osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); 145 if (!wsi) 146 { 147 osg::notify(osg::NOTICE)<<"View::setUpViewAcrossAllScreens() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl; 148 return 0; 149 } 150 151 unsigned int width, height; 152 wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); 156 osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); 153 157 154 width -= 500; 155 height -= 500; 158 osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get()); 159 if (gw) 160 { 161 osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<<gw<<std::endl; 156 162 157 osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; 158 traits->x = 500; 159 traits->y = 500; 160 traits->width = width; 161 traits->height = height; 162 #if 0 163 traits->windowDecoration = false; 164 #else 165 traits->windowDecoration = true; 166 #endif 167 traits->doubleBuffer = true; 168 traits->sharedContext = 0; 163 gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height ); 164 } 165 else 166 { 167 osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl; 168 } 169 169 170 osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); 170 unsigned int numCameras = 2; 171 double aspectRatioScale = 1.0/(double)numCameras; 172 for(unsigned int i=0; i<numCameras;++i) 173 { 174 osg::ref_ptr<osg::Camera> camera = new osg::Camera; 175 camera->setGraphicsContext(gc.get()); 176 camera->setViewport(new osg::Viewport((i*width)/numCameras,(i*height)/numCameras, width/numCameras, height/numCameras)); 177 GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; 178 camera->setDrawBuffer(buffer); 179 camera->setReadBuffer(buffer); 171 180 172 osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get()); 173 if (gw) 174 { 175 osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<<gw<<std::endl; 176 177 gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height ); 178 } 181 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::scale(aspectRatioScale,1.0,1.0)); 182 } 183 } 179 184 else 180 185 { 181 osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl; 186 viewer.setUpViewAcrossAllScreens(); 187 182 188 } 183 189 184 unsigned int numCameras = 2; 185 double aspectRatioScale = 1.0/(double)numCameras; 186 for(unsigned int i=0; i<numCameras;++i) 187 { 188 osg::ref_ptr<osg::Camera> camera = new osg::Camera; 189 camera->setGraphicsContext(gc.get()); 190 camera->setViewport(new osg::Viewport((i*width)/numCameras,(i*height)/numCameras, width/numCameras, height/numCameras)); 191 GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; 192 camera->setDrawBuffer(buffer); 193 camera->setReadBuffer(buffer); 190 // set up the camera manipulation with out custom manipultor 191 viewer.setCameraManipulator(new GliderManipulator()); 194 192 195 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::scale(aspectRatioScale,1.0,1.0));196 }193 // pass the scene graph to the viewer 194 viewer.setSceneData( createModel() ); 197 195 198 viewer.setUpRenderingSupport(); 199 viewer.assignSceneDataToCameras(); 200 201 #else 202 203 viewer.setUpViewAcrossAllScreens(); 204 205 #endif 206 207 viewer.realize(); 208 209 while( !viewer.done() ) 210 { 211 // fire off the cull and draw traversals of the scene. 212 viewer.frame(); 213 214 } 215 216 return 0; 196 return viewer.run(); 217 197 } 218 198
