Hi,
I believe that my previous post was not enough to elaborate the issue. So i am
attaching some code snippet of the problem i am having after doing minor
changes inside the osgdistortion.
***********************************************'
osg::ref_ptr<osg::Node> OSGQtMainWindow::createDistortedSubGraph(osg::Node
*subGraph, osg::Camera *cam)
{
osg::ref_ptr<osg::Group> distortedNode = new osg::Group;
//get the viewport of the camera
osg::ref_ptr<osg::Viewport> viewport = cam ? cam->getViewport() : 0;
unsigned int texture_width = int(viewport->width());
unsigned int texture_height = int(viewport->height());
//create a opengl texture state;
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D();
texture->setTextureSize(texture_width,texture_height);
texture->setInternalFormat(GL_RGBA);
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
//get the clearing color of the set camera
osg::Vec4 clearColor = cam->getClearColor();
//now setup to render to the texture camera
{
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setClearColor(clearColor);
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//NOW inherit the main camera view
camera->setReferenceFrame(osg::Transform::RELATIVE_RF);
camera->setProjectionMatrix(osg::Matrixd::identity());
camera->setViewMatrix(osg::Matrixd::identity());
//set the viewport of the camera
camera->setViewport(0,0,texture_width,texture_height);
//set the camera to render before the main camera
camera->setRenderOrder(osg::Camera::PRE_RENDER);
//tell the camera to use frame buffer object where supported
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
//attach the texture and use it as a color buffer
//means that the rendering will be done onto the texture
camera->attach(osg::Camera::COLOR_BUFFER,texture.get());
//add the subgraph as a child
//of the camera
//to render to the texture
camera->addChild(subGraph);
distortedNode->addChild(camera.get());
}
//set up the hud camera
{
//create a quad to visualize
osg::ref_ptr<osg::Geometry> polyGeom = new osg::Geometry;
osg::ref_ptr<osg::DrawArrays> polyGeomDA = new
osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4);
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
osg::ref_ptr<osg::Vec2Array> texcoords = new osg::Vec2Array;
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
vertices->push_back(osg::Vec3d(0,0,0));
vertices->push_back(osg::Vec3d(texture_width,0,0));
vertices->push_back(osg::Vec3d(texture_width,0,texture_height));
vertices->push_back(osg::Vec3d(0,0,texture_height));
texcoords->push_back(osg::Vec2(0,0));
texcoords->push_back(osg::Vec2(texture_width,0));
texcoords->push_back(osg::Vec2(texture_width,texture_height));
texcoords->push_back(osg::Vec2(0,texture_height));
polyGeom->setVertexArray(vertices.get());
polyGeom->setTexCoordArray(0,texcoords.get());
polyGeom->addPrimitiveSet(polyGeomDA.get());
polyGeom->setColorArray(colors.get());
polyGeom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
//get or create the stateset for this geometry
osg::ref_ptr<osg::StateSet> stateset = polyGeom->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0,texture.get(),osg::StateAttribute::ON);
stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
//create a geode
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(polyGeom.get());
//now setup the camera to render the textured quad
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
//inherit the main camera view
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrix::identity());
camera->setProjectionMatrixAsOrtho2D(0,texture_width,0,texture_height);
camera->setRenderOrder(osg::Camera::NESTED_RENDER);
camera->addChild(geode.get());
distortedNode->addChild(camera.get());
}
return distortedNode.get();
}
*****************************************'******
I really need some hint on it.
Thank you!
Cheers,
sajjad
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=34192#34192
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org