Show
Ignore:
Timestamp:
01/08/07 11:00:16 (8 years ago)
Author:
robert
Message:

Ported following examples to osgViewer:

osggeodemo
osggeometry
osghud
osgimpostor
osgkeyboard
osglauncher
osglight
osglightpoint
osglogicop
osglogo
osgmovie
osgmultiplecameras
osgmultitexture
osgoccluder
osgparametric
osgparticle

Files:
1 modified

Legend:

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

    r5636 r5927  
    11// -*-c++-*- 
    22 
    3 #include <osgProducer/Viewer> 
     3#include <osgViewer/Viewer> 
    44 
    55#include <osgDB/ReadFile> 
     
    1919#include <osgGA/EventVisitor> 
    2020 
     21#include <iostream> 
     22 
    2123osg::ImageStream* s_imageStream = 0; 
    22 class PostSwapFinishCallback : public Producer::Camera::Callback 
    23 { 
    24 public: 
    25  
    26     PostSwapFinishCallback() {} 
    27  
    28     virtual void operator()(const Producer::Camera& camera) 
    29     { 
    30         // osg::Timer_t start_tick = osg::Timer::instance()->tick(); 
    31          
    32         osgProducer::OsgSceneHandler* sh = const_cast<osgProducer::OsgSceneHandler*>(dynamic_cast<const osgProducer::OsgSceneHandler*>(camera.getSceneHandler())); 
    33      
    34         if (s_imageStream && s_imageStream->getPixelBufferObject()) s_imageStream->getPixelBufferObject()->compileBuffer(*(sh->getSceneView()->getState())); 
    35         // glFinish(); 
    36  
    37         //osg::notify(osg::NOTICE)<<"callback after PBO "<<osg::Timer::instance()->delta_m(start_tick,osg::Timer::instance()->tick())<<"ms"<<std::endl; 
    38     } 
    39 }; 
    40  
    4124class MovieEventHandler : public osgGA::GUIEventHandler 
    4225{ 
     
    134117        case(osgGA::GUIEventAdapter::RELEASE): 
    135118        { 
     119#if 0 
    136120            osgProducer::Viewer* viewer = dynamic_cast<osgProducer::Viewer*>(&aa); 
    137121            osgUtil::IntersectVisitor::HitList hlist; 
     
    206190     
    207191                    } 
    208  
    209192                }  
    210193            } 
     
    213196                osg::notify(osg::NOTICE)<<"No hit"<<std::endl; 
    214197            } 
     198#else 
     199            osg::notify(osg::NOTICE)<<"Need to implement picking."<<std::endl; 
     200#endif 
    215201            break; 
    216202        } 
     
    331317    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
    332318    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
     319    arguments.getApplicationUsage()->addCommandLineOption("--texture2D","Use Texture2D rather than TextureRectangle."); 
     320    arguments.getApplicationUsage()->addCommandLineOption("--shader","Use shaders to post process the video."); 
    333321     
    334322    bool useTextureRectangle = true; 
     
    336324 
    337325    // construct the viewer. 
    338     osgProducer::Viewer viewer(arguments); 
     326    osgViewer::Viewer viewer; 
    339327     
    340328    while (arguments.read("--texture2D")) useTextureRectangle=false; 
    341329    while (arguments.read("--shader")) useShader=true; 
    342  
    343     // set up the value with sensible default event handlers. 
    344     viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 
    345  
    346     // get details on keyboard and mouse bindings used by the viewer. 
    347     viewer.getUsage(*arguments.getApplicationUsage()); 
    348330 
    349331    // if user request help write it out to cout. 
     
    423405    { 
    424406        // nothing loaded. 
     407        arguments.getApplicationUsage()->write(std::cout); 
    425408        return 1; 
    426409    } 
    427      
    428      
    429410 
    430411    // pass the model to the MovieEventHandler so it can pick out ImageStream's to manipulate. 
     
    446427    } 
    447428 
    448  
    449     // any option left unread are converted into errors to write out later. 
    450     arguments.reportRemainingOptionsAsUnrecognized(); 
    451  
    452     // report any errors if they have occured when parsing the program aguments. 
    453     if (arguments.errors()) 
    454     { 
    455         arguments.writeErrorMessages(std::cout); 
    456     } 
    457 /* 
    458     // set up a post swap callback to flush deleted GL objects and compile new GL objects             
    459     for(unsigned int cameraNum=0;cameraNum<viewer.getNumberOfCameras();++cameraNum) 
    460     { 
    461         Producer::Camera* camera=viewer.getCamera(cameraNum); 
    462         camera->addPostSwapCallback(new PostSwapFinishCallback()); 
    463     } 
    464 */ 
    465429    // set the scene to render 
    466430    viewer.setSceneData(geode.get()); 
    467431 
    468432    // create the windows and run the threads. 
    469     viewer.realize(); 
    470  
    471     while( !viewer.done() ) 
    472     { 
    473         // wait for all cull and draw threads to complete. 
    474         viewer.sync(); 
    475          
    476         // update the scene by traversing it with the the update visitor which will 
    477         // call all node update callbacks and animations. 
    478         viewer.update(); 
    479           
    480         // fire off the cull and draw traversals of the scene. 
    481         viewer.frame(); 
    482          
    483     } 
    484      
    485     // wait for all cull and draw threads to complete. 
    486     viewer.sync(); 
    487  
    488     // run a clean up frame to delete all OpenGL objects. 
    489     viewer.cleanup_frame(); 
    490  
    491     // wait for all the clean up frame to complete. 
    492     viewer.sync(); 
    493  
    494     return 0; 
     433    return viewer.run(); 
    495434 
    496435