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

Ravi Mathur ravidavi at utexas.edu
Fri Mar 24 21:12:26 PDT 2017


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

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








More information about the osg-users mailing list