Show
Ignore:
Timestamp:
01/06/07 22:35:57 (7 years ago)
Author:
robert
Message:

Ported osgcopy, osgcubemap, osgdelaunay, osgdepthpartion, osgdistortion, osgfadetext, osgforest and osgfxbrowser to osgViewer

Files:
1 modified

Legend:

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

    r5582 r5923  
    1 #include <osgProducer/Viewer> 
     1#include <osgViewer/Viewer> 
    22 
    33#include <osg/Group> 
     
    2020#include <osgSim/SphereSegment> 
    2121 
    22 #include <osgGA/NodeTrackerManipulator> 
    23  
    24 class GraphicsContext { 
     22#include <osgGA/TerrainManipulator> 
     23 
     24#include <iostream> 
     25 
     26class MyGraphicsContext { 
    2527    public: 
    26         GraphicsContext() 
     28        MyGraphicsContext() 
    2729        { 
    28             rs = new Producer::RenderSurface; 
    29             rs->setWindowRectangle(0,0,1,1); 
    30             rs->useBorder(false); 
    31             rs->useConfigEventThread(false); 
    32             rs->realize(); 
     30            osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; 
     31            traits->x = 0; 
     32            traits->y = 0; 
     33            traits->width = 1; 
     34            traits->height = 1; 
     35            traits->windowDecoration = false; 
     36            traits->doubleBuffer = false; 
     37            traits->sharedContext = 0; 
     38            traits->pbuffer = true; 
     39 
     40            _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); 
     41 
     42            if (!_gc) 
     43            { 
     44                osg::notify(osg::NOTICE)<<"Failed to create pbuffer, failing back to normal graphics window."<<std::endl; 
     45                 
     46                traits->pbuffer = false; 
     47                _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); 
     48            } 
     49 
     50            if (_gc.valid())  
     51             
     52             
     53            { 
     54                _gc->realize(); 
     55                _gc->makeCurrent(); 
     56                std::cout<<"Realized window"<<std::endl; 
     57            } 
    3358        } 
    34  
    35         virtual ~GraphicsContext() 
    36         { 
    37         } 
     59         
     60        bool valid() const { return _gc.valid() && _gc->isRealized(); } 
    3861         
    3962    private: 
    40         Producer::ref_ptr<Producer::RenderSurface> rs; 
     63        osg::ref_ptr<osg::GraphicsContext> _gc; 
    4164}; 
    4265 
     
    6083            source->setCoordinateSystem(osgTerrain::DataSet::coordinateSystemStringToWTK("WGS84")); 
    6184 
    62              source->setGeoTransformPolicy(osgTerrain::DataSet::Source::PREFER_CONFIG_SETTINGS_BUT_SCALE_BY_FILE_RESOLUTION); 
    63              source->setGeoTransformFromRange(-180.0, 180.0, -90.0, 90.0); 
     85            source->setGeoTransformPolicy(osgTerrain::DataSet::Source::PREFER_CONFIG_SETTINGS_BUT_SCALE_BY_FILE_RESOLUTION); 
     86            source->setGeoTransformFromRange(-180.0, 180.0, -90.0, 90.0); 
    6487 
    6588            dataSet->addSource(source); 
     
    7497        dataSet->loadSources(); 
    7598 
    76         GraphicsContext context; 
     99        MyGraphicsContext context; 
    77100        dataSet->createDestination(30); 
    78101 
     
    153176 
    154177 
    155 int main(int argc, char **argv) 
    156 { 
    157     // use an ArgumentParser object to manage the program arguments. 
    158     osg::ArgumentParser arguments(&argc,argv); 
    159      
    160     // set up the usage document, in case we need to print out how to use this program. 
    161     arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of node tracker."); 
    162     arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()); 
    163     arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    164      
    165  
     178int main(int, char**) 
     179{ 
    166180    // construct the viewer. 
    167     osgProducer::Viewer viewer(arguments); 
    168  
    169     // set up the value with sensible default event handlers. 
    170     viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 
    171  
    172     viewer.getCullSettings().setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); 
    173     viewer.getCullSettings().setNearFarRatio(0.00001f); 
    174  
    175     // get details on keyboard and mouse bindings used by the viewer. 
    176     viewer.getUsage(*arguments.getApplicationUsage()); 
    177  
    178  
    179     // if user request help write it out to cout. 
    180     if (arguments.read("-h") || arguments.read("--help")) 
    181     { 
    182         arguments.getApplicationUsage()->write(std::cout); 
    183         return 1; 
    184     } 
    185  
    186     // any option left unread are converted into errors to write out later. 
    187     arguments.reportRemainingOptionsAsUnrecognized(); 
    188  
    189     // report any errors if they have occured when parsing the program aguments. 
    190     if (arguments.errors()) 
    191     { 
    192         arguments.writeErrorMessages(std::cout); 
    193         return 1; 
    194     } 
     181    osgViewer::Viewer viewer; 
     182 
     183    viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); 
     184    viewer.getCamera()->setNearFarRatio(0.00001f); 
    195185     
    196186    // read the scene from the list of file specified commandline args. 
     
    208198        csn->addChild(createFadeText(csn->getEllipsoidModel())); 
    209199    }     
    210          
    211  
    212     // create the windows and run the threads. 
    213     viewer.realize(); 
    214  
    215     while( !viewer.done() ) 
    216     { 
    217         // wait for all cull and draw threads to complete. 
    218         viewer.sync(); 
    219  
    220         // update the scene by traversing it with the the update visitor which will 
    221         // call all node update callbacks and animations. 
    222         viewer.update(); 
    223           
    224         // fire off the cull and draw traversals of the scene. 
    225         viewer.frame(); 
    226          
    227     } 
    228      
    229     // wait for all cull and draw threads to complete. 
    230     viewer.sync(); 
    231  
    232     // run a clean up frame to delete all OpenGL objects. 
    233     viewer.cleanup_frame(); 
    234  
    235     // wait for all the clean up frame to complete. 
    236     viewer.sync(); 
    237  
    238     return 0; 
     200 
     201    viewer.setCameraManipulator(new osgGA::TerrainManipulator); 
     202 
     203    return viewer.run(); 
    239204}