Show
Ignore:
Timestamp:
01/05/07 17:19:25 (7 years ago)
Author:
robert
Message:

Ported osgcallback to osgViewer

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgcallback/osgcallback.cpp

    r5381 r5914  
    1 #include <osgProducer/Viewer> 
     1#include <osgViewer/Viewer> 
    22 
    33#include <osg/Transform> 
     
    1616#include <osgUtil/Optimizer> 
    1717 
     18#include <iostream> 
    1819 
    1920class UpdateCallback : public osg::NodeCallback 
     
    123124    // use an ArgumentParser object to manage the program arguments. 
    124125    osg::ArgumentParser arguments(&argc,argv); 
    125  
    126     // set up the usage document, in case we need to print out how to use this program. 
    127     arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of the range of different types of callbacks supported in the OpenSceneGraph."); 
    128     arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
    129     arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    130126    
    131    // set the osgDB::Registy the read file callback to catch all requests for reading files. 
    132    osgDB::Registry::instance()->setReadFileCallback(new MyReadFileCallback()); 
     127    // set the osgDB::Registy the read file callback to catch all requests for reading files. 
     128    osgDB::Registry::instance()->setReadFileCallback(new MyReadFileCallback()); 
    133129    
    134130    // initialize the viewer. 
    135     osgProducer::Viewer viewer(arguments); 
    136  
    137     // set up the value with sensible default event handlers. 
    138     viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 
    139  
    140     // get details on keyboard and mouse bindings used by the viewer. 
    141     viewer.getUsage(*arguments.getApplicationUsage()); 
    142  
    143     // if user request help write it out to cout. 
    144     if (arguments.read("-h") || arguments.read("--help")) 
    145     { 
    146         arguments.getApplicationUsage()->write(std::cout); 
    147         return 1; 
    148     } 
    149  
    150     // any option left unread are converted into errors to write out later. 
    151     arguments.reportRemainingOptionsAsUnrecognized(); 
    152  
    153     // report any errors if they have occured when parsing the program aguments. 
    154     if (arguments.errors()) 
    155     { 
    156         arguments.writeErrorMessages(std::cout); 
    157         return 1; 
    158     } 
    159      
    160     if (arguments.argc()<=1) 
    161     { 
    162         arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
    163         return 1; 
    164     } 
     131    osgViewer::Viewer viewer; 
    165132 
    166133    // load the nodes from the commandline arguments. 
     
    168135    if (!rootnode) 
    169136    { 
    170 //        write_usage(osg::notify(osg::NOTICE),argv[0]); 
     137        osg::notify(osg::NOTICE)<<"Please specify a file on the command line"<<std::endl; 
     138 
    171139        return 1; 
    172140    } 
     
    183151    viewer.setSceneData(rootnode); 
    184152 
    185     // create the windows and run the threads. 
    186     viewer.realize(); 
    187  
    188     while( !viewer.done() ) 
    189     { 
    190         // wait for all cull and draw threads to complete. 
    191         viewer.sync(); 
    192  
    193         // update the scene by traversing it with the the update visitor which will 
    194         // call all node update callbacks and animations. 
    195         viewer.update(); 
    196           
    197         // fire off the cull and draw traversals of the scene. 
    198         viewer.frame(); 
    199          
    200     } 
    201      
    202     // wait for all cull and draw threads to complete. 
    203     viewer.sync(); 
    204  
    205     // run a clean up frame to delete all OpenGL objects. 
    206     viewer.cleanup_frame(); 
    207  
    208     // wait for all the clean up frame to complete. 
    209     viewer.sync(); 
    210  
    211     return 0; 
     153    return viewer.run(); 
    212154}