[osg-users] RTT CompositeViewer

John Donovan john.donovan at embryonicstudios.com
Thu Sep 6 09:15:22 PDT 2007


Hi all,
I'm using OSG 2.0.0 and I have a osgViewer::CompositeViewer which is made up
of several cameras looking at the scene from different points of view, and all
rendering into a regular GraphicsContext.
How can I set up my scene to render this composite view into a single texture?
I have some code that I've culled from various samples but it just gives me a
grey texture.

Image* im = new Image();
im->allocateImage(totalWidth, vpHeight, 1, GL_RGB, GL_BYTE);

Texture2D* rtt = new Texture2D(im);
rtt->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
rtt->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
rtt->setResizeNonPowerOfTwoHint(false);

// Rinse and repeat for each camera.
Camera* rttcamera = viewer.getView(0)->getCamera();
rttcamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
rttcamera->setClearColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
rttcamera->setRenderOrder(osg::Camera::PRE_RENDER);
rttcamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
rttcamera->attach(osg::Camera::COLOR_BUFFER, rtt);
rttcamera->setViewport(new Viewport(0.0, 0.0, vpWidth, vpHeight));
rttcamera->setProjectionMatrixAsPerspective(fovy, aspect, 1.0, 1000.0);
// Set up view matrix, GraphicsContext and whatnot.

// Later on I call this code to save the texture.
Camera::Attachment& foo = rttcamera->getBufferAttachmentMap().begin()->second;
Image* im = foo._texture->getImage(0);
if (im) {
   im->setFileName("c:\\temp\\test.png");
   osgDB::writeImageFile(*im, im->getFileName());
}

Is there a step that I'm missing?

-John Donovan


______________________________________________________________________
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