| 474 | | // use an ArgumentParser object to manage the program arguments. |
| 475 | | osg::ArgumentParser arguments(&argc,argv); |
| 476 | | |
| 477 | | // set up the usage document, in case we need to print out how to use this program. |
| 478 | | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of text."); |
| 479 | | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] [filename] ..."); |
| 480 | | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
| 481 | | |
| 482 | | |
| 484 | | osgProducer::Viewer viewer(arguments); |
| 485 | | |
| 486 | | // set up the value with sensible default event handlers. |
| 487 | | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
| 488 | | |
| 489 | | // get details on keyboard and mouse bindings used by the viewer. |
| 490 | | viewer.getUsage(*arguments.getApplicationUsage()); |
| 491 | | |
| 492 | | // if user request help write it out to cout. |
| 493 | | if (arguments.read("-h") || arguments.read("--help")) |
| 494 | | { |
| 495 | | arguments.getApplicationUsage()->write(std::cout); |
| 496 | | return 1; |
| 497 | | } |
| 498 | | |
| 499 | | // any option left unread are converted into errors to write out later. |
| 500 | | arguments.reportRemainingOptionsAsUnrecognized(); |
| 501 | | |
| 502 | | // report any errors if they have occured when parsing the program aguments. |
| 503 | | if (arguments.errors()) |
| 504 | | { |
| 505 | | arguments.writeErrorMessages(std::cout); |
| 506 | | return 1; |
| 507 | | } |
| 508 | | |
| 509 | | |
| 510 | | // read the scene from the list of file specified commandline args. |
| 511 | | osg::ref_ptr<osg::Node> rootNode = osgDB::readNodeFiles(arguments); |
| | 475 | osgViewer::Viewer viewer; |
| 556 | | } |
| 557 | | |
| 558 | | // set the scene to render |
| 559 | | viewer.setSceneData(rootNode.get()); |
| 560 | | |
| 561 | | |
| 562 | | // create the windows and run the threads. |
| 563 | | viewer.realize(); |
| 564 | | |
| 565 | | #if 0 |
| 566 | | // this optional compile block is done as a test against graphics |
| 567 | | // drivers that claim support for generate mip map, but the actual |
| 568 | | // implementation is flacky. It is not compiled by default. |
| 569 | | |
| 570 | | // go through each graphics context and switch off the generate mip map extension. |
| 571 | | // note, this must be done after the realize so that init of texture state and as |
| 572 | | // result extension structures have been iniatilized. |
| 573 | | for(unsigned int contextID = 0; |
| 574 | | contextID<viewer.getDisplaySettings()->getMaxNumberOfGraphicsContexts(); |
| 575 | | ++contextID) |
| 576 | | { |
| 577 | | osg::Texture::Extensions* textureExt = osg::Texture::getExtensions(contextID,false); |
| 578 | | if (textureExt) textureExt->setGenerateMipMapSupported(false); |
| 579 | | } |
| 580 | | #endif |
| 581 | | |
| 582 | | while( !viewer.done() ) |
| 583 | | { |
| 584 | | // wait for all cull and draw threads to complete. |
| 585 | | viewer.sync(); |
| 586 | | |
| 587 | | // update the scene by traversing it with the the update visitor which will |
| 588 | | // call all node update callbacks and animations. |
| 589 | | viewer.update(); |
| 590 | | |
| 591 | | // fire off the cull and draw traversals of the scene. |
| 592 | | viewer.frame(); |
| 593 | | |
| 594 | | } |
| 595 | | |
| 596 | | // wait for all cull and draw threads to complete. |
| 597 | | viewer.sync(); |
| 598 | | |
| 599 | | // run a clean up frame to delete all OpenGL objects. |
| 600 | | viewer.cleanup_frame(); |
| 601 | | |
| 602 | | // wait for all the clean up frame to complete. |
| 603 | | viewer.sync(); |
| 604 | | |
| 605 | | return 0; |
| | 500 | // set the scene to render |
| | 501 | viewer.setSceneData(group); |
| | 502 | } |
| | 503 | |
| | 504 | return viewer.run(); |