| 43 | | GraphicsContext() |
| 44 | | { |
| 45 | | rs = new Producer::RenderSurface; |
| 46 | | rs->setWindowRectangle(0,0,1,1); |
| 47 | | rs->useBorder(false); |
| 48 | | rs->useConfigEventThread(false); |
| 49 | | rs->realize(); |
| 50 | | } |
| 51 | | |
| 52 | | virtual ~GraphicsContext() |
| 53 | | { |
| 54 | | } |
| | 45 | MyGraphicsContext() |
| | 46 | { |
| | 47 | osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; |
| | 48 | traits->x = 0; |
| | 49 | traits->y = 0; |
| | 50 | traits->width = 1; |
| | 51 | traits->height = 1; |
| | 52 | traits->windowDecoration = false; |
| | 53 | traits->doubleBuffer = false; |
| | 54 | traits->sharedContext = 0; |
| | 55 | traits->pbuffer = true; |
| | 56 | |
| | 57 | _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); |
| | 58 | |
| | 59 | if (!_gc) |
| | 60 | { |
| | 61 | osg::notify(osg::NOTICE)<<"Failed to create pbuffer, failing back to normal graphics window."<<std::endl; |
| | 62 | |
| | 63 | traits->pbuffer = false; |
| | 64 | _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); |
| | 65 | } |
| | 66 | |
| | 67 | if (_gc.valid()) |
| | 68 | |
| | 69 | |
| | 70 | { |
| | 71 | _gc->realize(); |
| | 72 | _gc->makeCurrent(); |
| | 73 | std::cout<<"Realized window"<<std::endl; |
| | 74 | } |
| | 75 | } |
| | 76 | |
| | 77 | bool valid() const { return _gc.valid() && _gc->isRealized(); } |
| 220 | | osgProducer::Viewer viewer(arguments); |
| 221 | | |
| 222 | | // set up the value with sensible default event handlers. |
| 223 | | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
| 224 | | |
| 225 | | viewer.getCullSettings().setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); |
| 226 | | viewer.getCullSettings().setNearFarRatio(0.00001f); |
| 227 | | |
| 228 | | // get details on keyboard and mouse bindings used by the viewer. |
| 229 | | viewer.getUsage(*arguments.getApplicationUsage()); |
| | 243 | osgViewer::Viewer viewer; |
| | 244 | |
| | 245 | viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); |
| | 246 | viewer.getCamera()->setNearFarRatio(0.00001f); |
| | 247 | |
| 394 | | |
| 395 | | |
| 396 | | // create the windows and run the threads. |
| 397 | | viewer.realize(); |
| 398 | | |
| 399 | | while( !viewer.done() ) |
| 400 | | { |
| 401 | | // wait for all cull and draw threads to complete. |
| 402 | | viewer.sync(); |
| 403 | | |
| 404 | | // update the scene by traversing it with the the update visitor which will |
| 405 | | // call all node update callbacks and animations. |
| 406 | | viewer.update(); |
| 407 | | |
| 408 | | // fire off the cull and draw traversals of the scene. |
| 409 | | viewer.frame(); |
| 410 | | |
| 411 | | } |
| 412 | | |
| 413 | | // wait for all cull and draw threads to complete. |
| 414 | | viewer.sync(); |
| 415 | | |
| 416 | | // run a clean up frame to delete all OpenGL objects. |
| 417 | | viewer.cleanup_frame(); |
| 418 | | |
| 419 | | // wait for all the clean up frame to complete. |
| 420 | | viewer.sync(); |
| 421 | | |
| 422 | | return 0; |
| | 411 | return viewer.run(); |