Hi all,
I want to do an RTT of the current camera to do some PostProcesses on it (using shaders). When the geometry is textured, everything works ok, but when i use non-textured objects, the objects renders in black. I tryed the code in osgprerender example in my app and it does the same thing, but the osgprerender example works correctly (with the cessna model for ex.). I Attach an image of the result.
Here is the code i use:

   /// Texture for RTT ///
   {
       sourceSceneTexture = new osg::Texture2D;
       sourceSceneTexture->setTextureSize(textureWidth, textureHeight);
       sourceSceneTexture->setInternalFormat(GL_RGBA);
sourceSceneTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); sourceSceneTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
   }

   // Geode without ilumination for attaching the RTT
   rttPlaneGroup = new osg::Group;
   osg::ref_ptr<osg::Geode> geo = new osg::Geode;
   geo->setName("PlanoGeode");
   osg::StateSet* ss = geo->getOrCreateStateSet();
   ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
   finalPlaneGeometry = new osg::Geometry();

   finalPlaneGeometry->setName("PlanoGeometry");
   geo->addDrawable(finalPlaneGeometry.get());


   osg::Vec3Array* vertex = new osg::Vec3Array;
   vertex->push_back( osg::Vec3 (0,0,0) );  // down left
   vertex->push_back( osg::Vec3 (1,0,0) );  // down right
   vertex->push_back( osg::Vec3 (1,1,0) );  // up right
   vertex->push_back( osg::Vec3 (0,1,0) );  // up left
   finalPlaneGeometry->setVertexArray(vertex);

   GLuint vertplane[4] = {3,2,1,0};
finalPlaneGeometry->addPrimitiveSet(new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 4, vertplane));

   osg::Vec4Array* colors = new osg::Vec4Array;
   colors->push_back(osg::Vec4(1.0, 1.0, 1.0, 1.0));
   colors->push_back(osg::Vec4(1.0, 1.0, 1.0, 1.0));
   colors->push_back(osg::Vec4(1.0, 1.0, 1.0, 1.0));
   colors->push_back(osg::Vec4(1.0, 1.0, 1.0, 1.0));

   finalPlaneGeometry->setColorArray(colors);
   finalPlaneGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);


   osg::Vec2Array* tcoords = new osg::Vec2Array(4);
   (*tcoords)[0].set(0.0f, 0.0f);
   (*tcoords)[1].set(1.0f, 0.0f);
   (*tcoords)[2].set(1.0f, 1.0f);
   (*tcoords)[3].set(0.0f, 1.0f);
   finalPlaneGeometry->setTexCoordArray(0, tcoords);

   geo->addDrawable(finalPlaneGeometry);
   rttPlaneGroup->addChild(geo.get());


/////////////FBO - Scene////////////////////////////////////////////////////////
   // then create the camera node to do the render to texture
{ camShot = new osg::Camera;
       camShot->setName("CamShot");
       camShot->setClearColor(osg::Vec4(0.7,0.1,0.3,1));
       camShot->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       camShot->setProjectionMatrix(osg::Matrix::identity());
       camShot->setViewMatrix(osg::Matrix::identity());
       camShot->setReferenceFrame(osg::Transform::RELATIVE_RF);
       camShot->setViewport(0, 0, textureWidth, textureHeight);
       camShot->setRenderOrder(osg::Camera::PRE_RENDER);
camShot->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
       camShot->attach(osg::Camera::COLOR_BUFFER, sourceSceneTexture);
       camShot->addChild(root);
       rttPlaneGroup->addChild(camShot.get());
   }

   osg::ref_ptr<osg::Camera> camPlano = new osg::Camera;
   camPlano->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
   camPlano->setProjectionMatrixAsOrtho2D(0, 1, 0, 1);
   camPlano->setViewMatrix(osg::Matrix::identity());
   camPlano->setName("CamPlano");
   camPlano->setClearColor(osg::Vec4(0.0,0.0,0.0,1.0));
   camPlano->addChild(geo.get());
   rttPlaneGroup->addChild(camPlano.get());

   osg::StateSet* stateset = new osg::StateSet;
stateset->setTextureAttributeAndModes(0, sourceSceneTexture ,osg::StateAttribute::ON);
   rttPlaneGroup->setStateSet(stateset);

where root is the original scene and rttPlaneGroup the final render group.


Thanks in advance!!

J.

<<inline: cessna.jpg>>

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to