Show
Ignore:
Timestamp:
01/11/07 16:19:59 (8 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/osgtext/osgtext.cpp

    r5757 r5962  
    1818#include <osgDB/Registry> 
    1919 
    20 #include <osgProducer/Viewer> 
     20#include <osgViewer/Viewer> 
    2121 
    2222#include <osg/Geode> 
     
    470470} 
    471471 
    472 int main( int argc, char **argv ) 
     472int main(int , char **) 
    473473{ 
    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  
    483474    // construct the viewer. 
    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; 
    512476 
    513477    // prepare scene. 
    514478    { 
    515  
    516479        osg::Vec3 center(0.0f,0.0f,0.0f); 
    517480        float radius = 1.0f; 
    518481         
    519         if (rootNode.valid()) 
    520         { 
    521             // optimize the scene graph, remove rendundent nodes and state etc. 
    522             osgUtil::Optimizer optimizer; 
    523             optimizer.optimize(rootNode.get()); 
    524              
    525             const osg::BoundingSphere& bs = rootNode->getBound(); 
    526             center = bs.center(); 
    527             radius = bs.radius(); 
    528         } 
    529  
    530482        // make sure the root node is group so we can add extra nodes to it. 
    531         osg::Group* group = dynamic_cast<osg::Group*>(rootNode.get()); 
    532         if (!group) 
    533         { 
    534             group = new osg::Group; 
    535              
    536             if (rootNode.valid()) group->addChild(rootNode.get()); 
    537              
    538             rootNode = group; 
    539         } 
    540  
     483        osg::Group* group = new osg::Group; 
     484         
    541485        { 
    542486            // create the hud. 
     
    554498        group->addChild(create3DText(center,radius)); 
    555499 
    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(); 
    606505} 
    607506