[osg-users] Is it possible to temporarily redirect the main camera of a view?

Glenn Waldron gwaldron at gmail.com
Thu Mar 9 06:24:34 PST 2017


Werner,
I have never switched render targets at runtime before, but I have switched
attachments and needed to call camera->dirtyAttachmentMap() after calling
attach() or detach(). Maybe that will work.

Glenn Waldron

On Thu, Mar 9, 2017 at 9:10 AM, Werner Modenbach <Werner.Modenbach at texion.eu
> wrote:

> Hi all.
>
> Is it possible to redirect the main camera of a view temporarily to a FBO?
> It is my intention to get a snapshot of the scene with a modified
> projection matrix.
> I think about something like that:
>
> osg::ref_ptr<osg::Camera> camera = view->getCamera();
> osg::Camera::RenderTargetImplementation rti = camera->
> getRenderTargetImplementation();
> osg::Matrixd projectionMatrix = view->getCamera()->getProjectionMatrix();
>
> camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
>
> osg::ref_ptr<osg::Image> fbImage = new osg::Image;
>
> fbImage->allocateImage(width,height,1,GL_RGBA,GL_UNSIGNED_BYTE, 1);
>
>
> camera->attach( osg::Camera::COLOR_BUFFER, fbImage.get(), 0, 0);
>
> camera->setProjectionMatrix( projectionMatrix * offsetMatrix );
>
>
> view->frame();
>
> camera->setRenderTargetImplementation(rti);
> camera->detach( osg::Camera::COLOR_BUFFER );
>
> camera->setProjectionMatrix( projectionMatrix );
>
>
>
> I tried it but my screen gets updated on the frame()  call with the
> modified projection matrix
> and the image stays black.
>
> Thanks for any hints.
>
> - Werner -
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170309/0fc73ff2/attachment-0003.htm>


More information about the osg-users mailing list