Show
Ignore:
Timestamp:
01/11/07 16:19:59 (7 years ago)
Author:
robert
Message:

Ported following examples to osgViewer:

osgteapot
osgtessellate
osgtext
osgtexture1D
osgtexture2D
osgtexture3D
osgtexturerectangle
osgvertexprogram
osgvolume
osgwindows
osgsimple
osgkeyboardmouse

Files:
1 modified

Legend:

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

    r5763 r5962  
    77#include <osgDB/ReadFile> 
    88 
    9 #include <osgProducer/Viewer> 
     9#include <osgViewer/Viewer> 
    1010 
     11#include <iostream> 
    1112 
    1213// Creates a stateset which contains a 1D texture which is populated by contour banded color 
     
    143144    // use an ArgumentParser object to manage the program arguments. 
    144145    osg::ArgumentParser arguments(&argc,argv); 
    145  
    146     // set up the usage document, in case we need to print out how to use this program. 
    147     arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of 1D textures."); 
    148     arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
    149     arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    150146    
    151147    // construct the viewer. 
    152     osgProducer::Viewer viewer(arguments); 
    153  
    154     // set up the value with sensible default event handlers. 
    155     viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 
    156  
    157     // get details on keyboard and mouse bindings used by the viewer. 
    158     viewer.getUsage(*arguments.getApplicationUsage()); 
    159  
    160     // if user request help write it out to cout. 
    161     if (arguments.read("-h") || arguments.read("--help")) 
    162     { 
    163         arguments.getApplicationUsage()->write(std::cout); 
    164         return 1; 
    165     } 
    166  
    167     // any option left unread are converted into errors to write out later. 
    168     arguments.reportRemainingOptionsAsUnrecognized(); 
    169  
    170     // report any errors if they have occured when parsing the program aguments. 
    171     if (arguments.errors()) 
    172     { 
    173         arguments.writeErrorMessages(std::cout); 
    174         return 1; 
    175     } 
    176      
    177     if (arguments.argc()<=1) 
    178     { 
    179         arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
    180         return 1; 
    181     } 
     148    osgViewer::Viewer viewer; 
    182149 
    183150    // load the images specified on command line 
    184151    osg::Node* loadedModel = osgDB::readNodeFiles(arguments); 
    185  
    186152     
    187     if (loadedModel) 
    188     { 
    189  
    190         osg::StateSet* stateset = create1DTextureStateToDecorate(loadedModel); 
    191         if (!stateset) 
    192         { 
    193             std::cout<<"Error: failed to create 1D texture state."<<std::endl; 
    194             return 1; 
    195         } 
    196  
    197  
    198         loadedModel->setStateSet(stateset); 
    199         loadedModel->setUpdateCallback(new AnimateStateCallback()); 
    200  
    201         // add model to viewer. 
    202         viewer.setSceneData( loadedModel ); 
    203  
    204         // create the windows and run the threads. 
    205         viewer.realize(); 
    206  
    207         while( !viewer.done() ) 
    208         { 
    209             // wait for all cull and draw threads to complete. 
    210             viewer.sync(); 
    211  
    212             // update the scene by traversing it with the the update visitor which will 
    213             // call all node update callbacks and animations. 
    214             viewer.update(); 
    215  
    216             // fire off the cull and draw traversals of the scene. 
    217             viewer.frame(); 
    218  
    219         } 
    220      
    221         // wait for all cull and draw threads to complete. 
    222         viewer.sync(); 
    223  
    224         // run a clean up frame to delete all OpenGL objects. 
    225         viewer.cleanup_frame(); 
    226  
    227         // wait for all the clean up frame to complete. 
    228         viewer.sync(); 
    229     } 
    230     else 
     153    if (!loadedModel) 
    231154    { 
    232155        osg::notify(osg::NOTICE)<<arguments.getApplicationUsage()->getCommandLineUsage()<<std::endl; 
    233156        return 0; 
    234157    } 
    235      
    236      
    237      
    238     return 0; 
     158 
     159    osg::StateSet* stateset = create1DTextureStateToDecorate(loadedModel); 
     160    if (!stateset) 
     161    { 
     162        std::cout<<"Error: failed to create 1D texture state."<<std::endl; 
     163        return 1; 
     164    } 
     165 
     166 
     167    loadedModel->setStateSet(stateset); 
     168    loadedModel->setUpdateCallback(new AnimateStateCallback()); 
     169 
     170    // add model to viewer. 
     171    viewer.setSceneData( loadedModel ); 
     172 
     173    return viewer.run(); 
    239174}