[osg-users] Slave camera rendering

Zuzana Číková zuzana.cikova1 at gmail.com
Sat Apr 23 02:54:00 PDT 2011


Hi,

I used the masks as you suggested, and it works as I want, now I am trying to somehow make the viewport moveable, so it would look like magic lens. 

I was suggested to render the second, lens camera to texture so it could be made moveable in simplier way. 

This is my code for adding texture rendering 



Code:
osg::Texture2D* renderTexture = new osg::Texture2D;
renderTexture->setTextureSize(width()/2,height()/2);
renderTexture->setInternalFormat(GL_RGBA);
renderTexture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
renderTexture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
osg::ref_ptr<osg::Geometry> screenQuad;
screenQuad = osg::createTexturedQuadGeometry(osg::Vec3(),
osg::Vec3(width(), 0.0, 0.0),
osg::Vec3(0.0, height(), 0.0));
osg::ref_ptr<osg::Geode> quadGeode = new osg::Geode;
quadGeode->addDrawable(screenQuad.get());
osg::StateSet *quadState = quadGeode->getOrCreateStateSet();
quadState->setTextureAttributeAndModes(0, renderTexture, osg::StateAttribute::ON);


osg::ref_ptr<osg::Camera> orthoCamera = new osg::Camera;
orthoCamera->setProjectionMatrix(osg::Matrix::ortho2D(0, width()/2, 0, height()/2));
orthoCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
orthoCamera->setViewMatrix(osg::Matrix::identity());
orthoCamera->setViewport(0, 0, width()/2, height()/2);
orthoCamera->setRenderOrder(osg::Camera::POST_RENDER);
orthoCamera->addChild(quadGeode.get());

osg::ref_ptr<osg::Camera> camera2 = new osg::Camera;
camera2->setCullMask(0x2);
camera2->setGraphicsContext(getGraphicsWindow());
camera2->setViewport(new osg::Viewport(width()/2,height()/2,width()/2,height()/2));
camera2->setProjectionMatrixAsPerspective(60, static_cast<double>(width())/static_cast<double>(height()), 0.01, appConf->getValue("Viewer.Display.ViewDistance").toFloat());
//camera2->setViewMatrixAsLookAt(osg::Vec3d(-10, 0, 0), osg::Vec3d(0, 0, 0), osg::Vec3d(0, 1, 0));
//camera2->setReferenceFrame(osg::Transform::RELATIVE_RF);
camera2->setRenderOrder(osg::Camera::PRE_RENDER);
camera2->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
camera2->attach(osg::Camera::COLOR_BUFFER, renderTexture); 

addSlave(camera2.get(), osg::Matrixd::translate(0.0,0.0,0.0), osg::Matrixd());
addSlave(orthoCamera.get(), osg::Matrixd::translate(0.0,0.0,0.0), osg::Matrixd());





But I get this writing to ouput in infinite loop:

Warning: detected OpenGL error 'invalid value' at start of State::apply().

I don't know if I understood correctly the RTT, now I have three cameras, one main and two for one RTT, is it correct? And the RTT for moving lens, is it good way to do this?


Thank you very much!

Cheers,
Zuzana

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








More information about the osg-users mailing list