Show
Ignore:
Timestamp:
05/26/08 17:41:54 (7 years ago)
Author:
robert
Message:

Added basic --pbuffer width height support

Files:
1 modified

Legend:

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

    r8344 r8345  
    687687 
    688688     
     689    unsigned int width=1280; 
     690    unsigned int height=1024; 
     691    osg::ref_ptr<osg::GraphicsContext> pbuffer; 
     692    if (arguments.read("--pbuffer",width,height)) 
     693    { 
     694        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; 
     695        traits->x = 0; 
     696        traits->y = 0; 
     697        traits->width = width; 
     698        traits->height = height; 
     699        traits->red = 8; 
     700        traits->green = 8; 
     701        traits->blue = 8; 
     702        traits->alpha = 8; 
     703        traits->windowDecoration = false; 
     704        traits->pbuffer = true; 
     705        traits->doubleBuffer = true; 
     706        traits->sharedContext = 0; 
     707 
     708        pbuffer = osg::GraphicsContext::createGraphicsContext(traits.get()); 
     709        if (pbuffer.valid()) 
     710        { 
     711            osg::notify(osg::NOTICE)<<"Pixel buffer has been created successfully."<<std::endl; 
     712        } 
     713        else 
     714        { 
     715            osg::notify(osg::NOTICE)<<"Pixel buffer has not been created successfully."<<std::endl; 
     716        } 
     717 
     718    } 
    689719         
    690720    // load the data 
     
    715745    viewer.realize(); 
    716746     
    717     addCallbackToViewer(viewer, new WindowCaptureCallback(mode, position, readBuffer)); 
     747    if (pbuffer.valid()) 
     748    { 
     749        viewer.stopThreading(); 
     750         
     751        pbuffer->realize(); 
     752     
     753        osg::ref_ptr<osg::Camera> camera = new osg::Camera; 
     754        camera->setGraphicsContext(pbuffer.get()); 
     755        camera->setViewport(new osg::Viewport(0,0,width,height)); 
     756        GLenum buffer = pbuffer->getTraits()->doubleBuffer ? GL_BACK : GL_FRONT; 
     757        camera->setDrawBuffer(buffer); 
     758        camera->setReadBuffer(buffer); 
     759        camera->setFinalDrawCallback(new WindowCaptureCallback(mode, position, readBuffer)); 
     760 
     761        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); 
     762         
     763        viewer.startThreading(); 
     764    } 
     765    else 
     766    { 
     767        addCallbackToViewer(viewer, new WindowCaptureCallback(mode, position, readBuffer)); 
     768    } 
    718769 
    719770    return viewer.run();