Question

I need to capture an Image from my viewer and need to do some post processing and display it back on it. Right now am more interested in the first part of it. That is to capture Image from the viewer.

While going through the OSG I came across ScreenCaptureHandler. But am not able to get an Image out of it.

I am still working to get it done but in case any of you have any other way of how it can be done or an Example for screencapturehandler that you can share.

Was it helpful?

Solution

To capture the rendered view into an image I use a custom osg::Camera::DrawCallback.

To capture the view at any point, set the drawCallback on the camera, force rendering, restore to a NULL callback.

Notice that the following code is part of a member function of a custom viewer (that's probably not your case):

osgViewer::View::getCamera()->setFinalDrawCallback(new ViewCaptureCallback(img));
osgViewer::Viewer::renderingTraversals();
osgViewer::View::getCamera()->setFinalDrawCallback(NULL);

The ViewCaptureCallback basically uses image->readPixels() to read from the backbuffer.

glReadBuffer( GL_BACK ); 
osg::GraphicsContext* gc = renderInfo.getState()->getGraphicsContext(); 
// Here you should process the backbuffer's size and format
image->readPixels(0, 0, gc->getTraits()->width, gc->getTraits()->height, pixelFormat, GL_UNSIGNED_BYTE);

Hope it helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top