Show
Ignore:
Timestamp:
01/11/07 12:47:01 (8 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/osgspacewarp/osgspacewarp.cpp

    r5381 r5959  
    1515#include <osgDB/ReadFile> 
    1616#include <osgUtil/Optimizer> 
    17 #include <osgProducer/Viewer> 
     17#include <osgViewer/Viewer> 
    1818 
    1919float random(float min,float max) { return min + (max-min)*(float)rand()/(float)RAND_MAX; } 
     
    114114int main( int argc, char **argv ) 
    115115{ 
    116  
    117     // use an ArgumentParser object to manage the program arguments. 
    118     osg::ArgumentParser arguments(&argc,argv); 
    119      
    120     // set up the usage document, in case we need to print out how to use this program. 
    121     arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); 
    122     arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" example demonstrate how to use a draw callback to create a space warp effect ."); 
    123     arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
    124     arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    125      
    126  
    127116    // construct the viewer. 
    128     osgProducer::Viewer viewer(arguments); 
    129  
    130     // set up the value with sensible default event handlers. 
    131     viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 
    132  
    133     // get details on keyboard and mouse bindings used by the viewer. 
    134     viewer.getUsage(*arguments.getApplicationUsage()); 
    135  
    136     // if user request help write it out to cout. 
    137     if (arguments.read("-h") || arguments.read("--help")) 
    138     { 
    139         arguments.getApplicationUsage()->write(std::cout); 
    140         return 1; 
    141     } 
    142  
    143     // report any errors if they have occured when parsing the program aguments. 
    144     if (arguments.errors()) 
    145     { 
    146         arguments.writeErrorMessages(std::cout); 
    147         return 1; 
    148     } 
    149      
    150  
    151     // read the scene from the list of file specified commandline args. 
    152     osg::ref_ptr<osg::Node> loadedModel = createScene(50000); 
    153  
    154     // if no model has been successfully loaded report failure. 
    155     if (!loadedModel)  
    156     { 
    157         std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; 
    158         return 1; 
    159     } 
    160  
    161     // any option left unread are converted into errors to write out later. 
    162     arguments.reportRemainingOptionsAsUnrecognized(); 
    163  
    164     // report any errors if they have occured when parsing the program aguments. 
    165     if (arguments.errors()) 
    166     { 
    167         arguments.writeErrorMessages(std::cout); 
    168     } 
     117    osgViewer::Viewer viewer; 
    169118 
    170119    // set the scene to render 
    171     viewer.setSceneData(loadedModel.get()); 
     120    viewer.setSceneData(createScene(50000)); 
    172121 
    173     // create the windows and run the threads. 
    174     viewer.realize(); 
    175  
    176     while( !viewer.done() ) 
    177     { 
    178         // wait for all cull and draw threads to complete. 
    179         viewer.sync(); 
    180  
    181         // update the scene by traversing it with the the update visitor which will 
    182         // call all node update callbacks and animations. 
    183         viewer.update(); 
    184           
    185         // fire off the cull and draw traversals of the scene. 
    186         viewer.frame(); 
    187          
    188     } 
    189      
    190     // wait for all cull and draw threads to complete. 
    191     viewer.sync(); 
    192  
    193     // run a clean up frame to delete all OpenGL objects. 
    194     viewer.cleanup_frame(); 
    195  
    196     // wait for all the clean up frame to complete. 
    197     viewer.sync(); 
    198  
    199     return 0; 
     122    return viewer.run(); 
    200123} 
    201124