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

2017-03-24 Thread Ravi Mathur
Hi Werner,

Instead of modifying the main camera attachments, you might want to create a 
slave camera whose sole purpose is to render to FBO. Then you can 
enable/disable that camera using slaveCamera->setNodeMask (0x0 to disable, 
0x) to enable.


Code:

// Create slave camera and set its attachment
osg::Camera *slaveCamera = new osg::Camera;
slaveCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
/** Create & attach your image here */

// Add slave camera to view and set its projection offset matrix
view->addSlave(slaveCamera, true) // true = use master camera's scene
osg::View::Slave *theSlave = view->findSlaveForCamera(slaveCamera);
theSlave->_projectionOffset = offsetMatrix;

// Enable slave when you want to render to FBO
slaveCamera->setNodeMask(0x);

// Disable camera on the next frame
slaveCamera->setNodeMask(0x0);

// Profit




Hope this helps,
Ravi

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


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

2017-03-10 Thread Werner Modenbach

Hi Glen,

thanks for the hint. I'm still sticking with version 3.2 and this method 
is not available there.

I will try to move to the latest version and do like you suggested.

Thanks

- Werner -

Am 09.03.2017 um 15:24 schrieb Glenn Waldron:

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 
> 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 camera = view->getCamera();
osg::Camera::RenderTargetImplementation rti =
camera->getRenderTargetImplementation();
osg::MatrixdprojectionMatrix=view->getCamera()->getProjectionMatrix();
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
osg::ref_ptr fbImage=newosg::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@lists.openscenegraph.org

http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


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

2017-03-09 Thread Glenn Waldron
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  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 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 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@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


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

2017-03-09 Thread Werner Modenbach

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 camera = view->getCamera();
osg::Camera::RenderTargetImplementation rti = 
camera->getRenderTargetImplementation();

osg::MatrixdprojectionMatrix=view->getCamera()->getProjectionMatrix();

camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);

osg::ref_ptr fbImage=newosg::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@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org