[osg-users] FBO question

John Donovan john.donovan at embryonicstudios.com
Mon Sep 17 02:44:38 PDT 2007

Igor Naigovzin wrote:
> Hello to all!
> I have a simple question.
> I want to render a two cameras (two different render surfaces) by exactly
> the same scene.

Hi Igor,
if I understand you correctly, you're doing the same sort of thing I am. I have
a few cameras rendering to the same texture.
This is the code I use:
ref_ptr<GraphicsContext::Traits> traits = new GraphicsContext::Traits;
traits->x = 500;
traits->y = 800;
traits->width = totalWidth;
traits->height = vpHeight;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0;
ref_ptr<GraphicsContext> _gc =

osgViewer::Viewer _viewer;

for (int i = 0; i < _numCameras; ++i) {
   rot.makeRotate(_startAng + (_angStep * i), 0.0, 1.0, 0.0);
   ref_ptr<Camera> cam = new Camera;
   cam->setViewport(new Viewport(_cameraWidth * i, 0.0, _cameraWidth,
   cam->attach(Camera::COLOR_BUFFER, _texture.get());

   _viewer.addSlave(cam.get(), Matrixd(), rot, false);

_viewer.getCamera()->setProjectionMatrixAsPerspective(_cameraFoVX /
_aspectRatio, _aspectRatio, 1.0, 1000.0);
_viewer.getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
_viewer.getCamera()->setClearColor(Vec4(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX));

I'm using a floating-point texture, but it works just as well with a regular
8-bit RGB texture. Note I'm setting up the viewports for each camera. My
application is a piecewise linear approximation of a cylindrical projection.
I then set up another viewer and another scene graph to render the textured
quad to the screen, then call _both_ viewers in my render loop.

Hope this helps,

This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 

More information about the osg-users mailing list