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/osgcatch/osgcatch.cpp

    r5900 r5962  
    13541354 
    13551355 
    1356 #if 0 
    1357  
    1358 #include <osgProducer/Viewer> 
    1359  
    1360 class CompileStateCallback : public osgProducer::OsgCameraGroup::RealizeCallback 
    1361 { 
    1362     public: 
    1363         CompileStateCallback(GameEventHandler* eh):_gameEventHandler(eh) {} 
    1364          
    1365         virtual void operator()( osgProducer::OsgCameraGroup&, osgProducer::OsgSceneHandler& sh, const Producer::RenderSurface& ) 
    1366         {  
    1367             // now safe to construct 
    1368             sh.init(); 
    1369            
    1370             { 
    1371                 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); 
    1372  
    1373                 if (_gameEventHandler) 
    1374                 { 
    1375                     _gameEventHandler->compileGLObjects(*(sh.getSceneView()->getState())); 
    1376                 } 
    1377             } 
    1378         } 
    1379          
    1380          
    1381         OpenThreads::Mutex  _mutex; 
    1382         GameEventHandler*  _gameEventHandler; 
    1383          
    1384 }; 
     1356#include <osgViewer/Viewer> 
     1357#include <iostream> 
    13851358 
    13861359int main( int argc, char **argv ) 
     
    13981371    arguments.getApplicationUsage()->addCommandLineOption("-y <float>","Vertical offset of left and right images."); 
    13991372    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    1400      
    1401  
    1402     // construct the viewer. 
    1403     osgProducer::Viewer viewer(arguments); 
    1404  
    1405     // set up the value with sensible default event handlers. 
    1406     viewer.setUpViewer(osgProducer::Viewer::ESCAPE_SETS_DONE); 
    1407  
    1408     // register the handler to add keyboard and mosue handling. 
    1409     GameEventHandler* seh = new GameEventHandler(); 
    1410     viewer.getEventHandlerList().push_front(seh); 
    1411  
    1412     while (arguments.read("--boy")) seh->addPlayer(GameEventHandler::PLAYER_BOY); 
    1413     while (arguments.read("--girl")) seh->addPlayer(GameEventHandler::PLAYER_GIRL); 
    1414      
    1415      
    1416  
    1417     // get details on keyboard and mouse bindings used by the viewer. 
    1418     viewer.getUsage(*arguments.getApplicationUsage()); 
    1419  
    1420     // if user request help write it out to cout. 
    1421     if (arguments.read("-h") || arguments.read("--help")) 
    1422     { 
    1423         arguments.getApplicationUsage()->write(std::cout); 
    1424         return 1; 
    1425     } 
    1426  
    1427     // any option left unread are converted into errors to write out later. 
    1428     arguments.reportRemainingOptionsAsUnrecognized(); 
    1429  
    1430     // report any errors if they have occured when parsing the program aguments. 
    1431     if (arguments.errors()) 
    1432     { 
    1433         arguments.writeErrorMessages(std::cout); 
    1434         return 1; 
    1435     } 
    1436      
    1437     // now the windows have been realized we switch off the cursor to prevent it 
    1438     // distracting the people seeing the stereo images. 
    1439     float fovy = 1.0f; 
    1440     for( unsigned int i = 0; i < viewer.getNumberOfCameras(); i++ ) 
    1441     { 
    1442         Producer::Camera* cam = viewer.getCamera(i); 
    1443         Producer::RenderSurface* rs = cam->getRenderSurface(); 
    1444         rs->useCursor(false); 
    1445         fovy = osg::DegreesToRadians(cam->getLensVerticalFov()); 
    1446     } 
    1447      
    1448     seh->setFOVY(fovy); 
    1449      
    1450     // enable the image cache so we don't need to keep loading the particle files 
    1451     osgDB::ReaderWriter::Options* options = new osgDB::ReaderWriter::Options; 
    1452     options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_IMAGES); 
    1453     osgDB::Registry::instance()->setOptions(options); 
    1454  
    1455  
    1456     // creat the scene from the file list. 
    1457     osg::ref_ptr<osg::Node> rootNode = seh->createScene(); 
    1458  
    1459     //osgDB::writeNodeFile(*rootNode,"test.osg"); 
    1460  
    1461     // set the scene to render 
    1462     viewer.setSceneData(rootNode.get()); 
    1463  
    1464     viewer.setRealizeCallback(new CompileStateCallback(seh)); 
    1465  
    1466     // create the windows and run the threads, note has to be single threaded 
    1467     // due to use osgParticle 
    1468     viewer.realize(Producer::CameraGroup::SingleThreaded); 
    1469      
    1470     viewer.requestWarpPointer(0.5f,0.5f); 
    1471          
    1472  
    1473     while( !viewer.done() ) 
    1474     { 
    1475         // wait for all cull and draw threads to complete. 
    1476         viewer.sync(); 
    1477  
    1478         // update the scene by traversing it with the the update visitor which will 
    1479         // call all node update callbacks and animations. 
    1480         viewer.update(); 
    1481           
    1482         viewer.setView(seh->getCameraPosition()); 
    1483  
    1484         // fire off the cull and draw traversals of the scene. 
    1485         viewer.frame(); 
    1486          
    1487     } 
    1488  
    1489     // wait for all cull and draw threads to complete. 
    1490     viewer.sync(); 
    1491  
    1492     // run a clean up frame to delete all OpenGL objects. 
    1493     viewer.cleanup_frame(); 
    1494  
    1495     // wait for all the clean up frame to complete. 
    1496     viewer.sync(); 
    1497      
    1498     return 0; 
    1499 } 
    1500 #else 
    1501  
    1502 #include <osgViewer/Viewer> 
    1503 #include <iostream> 
    1504  
    1505 int main( int argc, char **argv ) 
    1506 { 
    1507  
    1508     // use an ArgumentParser object to manage the program arguments. 
    1509     osg::ArgumentParser arguments(&argc,argv); 
    1510      
    1511     // set up the usage document, in case we need to print out how to use this program. 
    1512     arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use node masks to create stereo images."); 
    1513     arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye"); 
    1514     arguments.getApplicationUsage()->addCommandLineOption("-d <float>","Time delay in sceonds between the display of successive image pairs when in auto advance mode."); 
    1515     arguments.getApplicationUsage()->addCommandLineOption("-a","Enter auto advance of image pairs on start up."); 
    1516     arguments.getApplicationUsage()->addCommandLineOption("-x <float>","Horizontal offset of left and right images."); 
    1517     arguments.getApplicationUsage()->addCommandLineOption("-y <float>","Vertical offset of left and right images."); 
    1518     arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    15191373 
    15201374    // construct the viewer. 
     
    15991453    return 0; 
    16001454} 
    1601  
    1602 #endif