Show
Ignore:
Timestamp:
01/11/07 12:47:01 (7 years ago)
Author:
robert
Message:

Ported follow examples to osgViewer:

osgshape
osgsimplifier
osgsimulation
osgslice
osgspacewarp
osgspheresegment
osgspotlight
osgstereoimage

Files:
1 modified

Legend:

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

    r5381 r5959  
    44#include <osg/Texture2D> 
    55 
    6 #include <osgProducer/Viewer> 
     6#include <osgViewer/Viewer> 
    77 
    88#include <osgDB/ReadFile> 
     
    1313#include "../osghangglide/terrain_coords.h" 
    1414 
    15 osg::Geode* createShapes( char* img_filename ) 
     15osg::Geode* createShapes() 
    1616{ 
    1717    osg::Geode* geode = new osg::Geode(); 
     
    2222    osg::StateSet* stateset = new osg::StateSet(); 
    2323 
    24     if( ! img_filename ) img_filename = "Images/lz.rgb"; 
    25     osg::Image* image = osgDB::readImageFile( img_filename ); 
     24    osg::Image* image = osgDB::readImageFile( "Images/lz.rgb" ); 
    2625 
    2726    if (image) 
     
    8685} 
    8786 
    88 int main( int argc, char **argv ) 
     87int main(int, char **) 
    8988{ 
    90  
    91     // use an ArgumentParser object to manage the program arguments. 
    92     osg::ArgumentParser arguments(&argc,argv); 
    93  
    94     // set up the usage document, in case we need to print out how to use this program. 
    95     arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates the osg::Shape classes."); 
    96     arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] [image_filename]"); 
    97     arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    98     
    9989    // construct the viewer. 
    100     osgProducer::Viewer viewer(arguments); 
    101  
    102     // set up the value with sensible default event handlers. 
    103     viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 
    104  
    105     // get details on keyboard and mouse bindings used by the viewer. 
    106     viewer.getUsage(*arguments.getApplicationUsage()); 
    107  
    108     // if user request help write it out to cout. 
    109     if (arguments.read("-h") || arguments.read("--help")) 
    110     { 
    111         arguments.getApplicationUsage()->write(std::cout); 
    112         return 1; 
    113     } 
    114  
    115     // any option left unread are converted into errors to write out later. 
    116     arguments.reportRemainingOptionsAsUnrecognized(); 
    117  
    118     // report any errors if they have occured when parsing the program aguments. 
    119     if (arguments.errors()) 
    120     { 
    121         arguments.writeErrorMessages(std::cout); 
    122         return 1; 
    123     } 
    124  
    125     char* img_filename = 0; 
    126     for( int pos = 1; pos < arguments.argc(); ++pos ) 
    127     { 
    128         if( arguments.isString(pos) ) 
    129         { 
    130             img_filename = arguments[pos]; 
    131             break; 
    132         } 
    133     } 
    134      
    135     osg::Node* node = createShapes( img_filename ); 
     90    osgViewer::Viewer viewer; 
    13691 
    13792    // add model to viewer. 
    138     viewer.setSceneData( node ); 
     93    viewer.setSceneData( createShapes() ); 
    13994 
    140     // create the windows and run the threads. 
    141     viewer.realize(); 
    142  
    143     while( !viewer.done() ) 
    144     { 
    145         // wait for all cull and draw threads to complete. 
    146         viewer.sync(); 
    147  
    148         // update the scene by traversing it with the the update visitor which will 
    149         // call all node update callbacks and animations. 
    150         viewer.update(); 
    151           
    152         // fire off the cull and draw traversals of the scene. 
    153         viewer.frame(); 
    154          
    155     } 
    156      
    157     // wait for all cull and draw threads to complete. 
    158     viewer.sync(); 
    159  
    160     // run a clean up frame to delete all OpenGL objects. 
    161     viewer.cleanup_frame(); 
    162  
    163     // wait for all the clean up frame to complete. 
    164     viewer.sync(); 
    165  
    166     return 0; 
     95    return viewer.run(); 
    16796}