[osg-users] How to read FBO attachment back to the CPU?

Marius Dransfeld marius.dransfeld at gmail.com
Fri Jan 6 04:05:33 PST 2017


Hi,

I have a scene graph that contains a (pre-render) camera that renders to an FBO with an attached image. Similar to this:

Code:

cam = new osg::Camera;
cam->setRenderOrder(osg::Camera::PRE_RENDER);
cam->setRenderTargetImplementation(DsTOsgCamera::FRAME_BUFFER_OBJECT);
cam->attach(osg::Camera::COLOR_BUFFER, m_RenderTarget, 0, 0, false, 1, 0);




Now I want to read the pixel data of that image back to the CPU each frame.
I tried using a DrawCall back:

Code:

class ImageReader : public osg::Camera::DrawCallback
{
public:
virtual void operator() (osg::RenderInfo& renderInfo) const
{
osg::ref_ptr<osg::Camera> camera = renderInfo.getCurrentCamera();
int x, y, width, height;
x = camera->getViewport()->x();
y = camera->getViewport()->y();
width = camera->getViewport()->width();
height = camera->getViewport()->height();

osg::ref_ptr<osg::Image> image = new osg::Image;
image->readPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE);

osgDB::writeImageFile(*image,"image.png");
}
}



and adding it to the camera:

Code:

cam->setFinalDrawCallback(new ImageReader());




What happens is that not the rendered image of that camera is captured, but instead the output of the whole scene graph.
How can I correctly access the rendering result of an FBO camera?

Thank you!

Cheers,
Marius

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=69901#69901








More information about the osg-users mailing list