OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Is it possible to temporarily redirect the main camera of a view?


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
wernerM
User


Joined: 06 Feb 2013
Posts: 60

PostPosted: Thu Mar 09, 2017 2:13 pm    Post subject:
Is it possible to temporarily redirect the main camera of a view?
Reply with quote

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;
Quote:
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 );
Quote:
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 -

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
gwaldron (Glenn Waldron)
Appreciator


Joined: 25 Aug 2011
Posts: 192

PostPosted: Thu Mar 09, 2017 2:27 pm    Post subject:
Is it possible to temporarily redirect the main camera of a view?
Reply with quote

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 < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
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;
Quote:
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 );
Quote:
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
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
wernerM
User


Joined: 06 Feb 2013
Posts: 60

PostPosted: Fri Mar 10, 2017 11:00 am    Post subject:
Is it possible to temporarily redirect the main camera of a view?
Reply with quote

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:

Quote:
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 < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
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;
Quote:
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 );
Quote:
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 (
Only registered users can see emails on this board!
Get registred or enter the forums!
) http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Quote:
_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
ravidavi
User


Joined: 06 Nov 2015
Posts: 32

PostPosted: Sat Mar 25, 2017 4:12 am    Post subject:
Reply with quote

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, 0xffffffff) 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(0xffffffff);

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

// Profit


Hope this helps,
Ravi
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts How to get the camera's roll pitch an... xdfanfan General 1 Sat Apr 01, 2017 8:43 am View latest post
No new posts Multisampled FBO camera with shared d... HonzaS General 0 Fri Mar 17, 2017 3:19 pm View latest post
No new posts About separate rendering of a slave c... wernerM General 0 Tue Mar 07, 2017 3:14 pm View latest post
No new posts Change Perspective to Orthogonal View romulogcerqueira General 1 Mon Mar 06, 2017 12:51 am View latest post
No new posts [3rdParty/maybe OSG general] osgoculu... Trajce Nikolov NICK General 2 Wed Mar 01, 2017 11:24 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP