Hi,

I'm using the code below, mixture taken from the examples.
It's only rendering black. Anything I'm doing wrong?

Thank you!

The  function takes a node providing a new scene, and a back color.
It returns a node containing a quad with the texture being the new scene 
rendered to it.


Code:
osg::Node* create(osg::Node* subgraph, const osg::Vec4& clearColour)
{
    osg::Group* distortionNode = new osg::Group;
    
    unsigned int tex_width = 1024;
    unsigned int tex_height = 1024;
    
    osg::Texture2D* texture = new osg::Texture2D;
    texture->setTextureSize(tex_width, tex_height);
    texture->setInternalFormat(GL_RGBA);
    texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
    texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
   
    // set up the render to texture camera.
    {
        osg::Camera* camera = new osg::Camera;

        // set clear the color and depth buffer
        camera->setClearColor(clearColour);
        camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        // just inherit the main cameras view
        camera->setReferenceFrame(osg::Transform::RELATIVE_RF);
        camera->setProjectionMatrix(osg::Matrixd::identity());
        camera->setViewMatrix(osg::Matrixd::identity());

        // set viewport
        camera->setViewport(0,0,tex_width,tex_height);

        // set the camera to render before the main camera.
        camera->setRenderOrder(osg::Camera::PRE_RENDER);

        // tell the camera to use OpenGL frame buffer object where supported.
        camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);

        // attach the texture and use it as the color buffer.
        camera->attach(osg::Camera::COLOR_BUFFER, texture);

        // add subgraph to render
        camera->addChild(subgraph);
        
        distortionNode->addChild(camera);
   }
    
    {
        osg::Geometry* polyGeom = new osg::Geometry;

            osg::Vec3Array* vertices = new osg::Vec3Array;
            float depth = 10.f;
            vertices->push_back(osg::Vec3(-20,20,depth));
            vertices->push_back(osg::Vec3(-20,-20,depth));
            vertices->push_back(osg::Vec3(20,-20,depth));
            vertices->push_back(osg::Vec3(20,20,depth));
            polyGeom->setVertexArray(vertices);

            osg::Vec3Array* normals = new osg::Vec3Array;
            normals->push_back(osg::Vec3(0.0f,0.0f,1.0f));
            polyGeom->setNormalArray(normals);
            polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);

            osg::Vec4Array* colors = new osg::Vec4Array;
            colors->push_back(osg::Vec4(1.0f,1.0f,1.f,1.0f));
            polyGeom->setColorArray(colors);
            polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);

            polyGeom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));


        // new we need to add the texture to the Drawable, we do so by creating 
a 
        // StateSet to contain the Texture StateAttribute.
        osg::StateSet* stateset = polyGeom->getOrCreateStateSet();
        stateset->setTextureAttributeAndModes(0, 
texture,osg::StateAttribute::ON);
        stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);

        osg::Geode* geode = new osg::Geode();
        geode->addDrawable(polyGeom);

        distortionNode->addChild(geode);
    }
    return distortionNode;
}



Cheers,
Paul

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





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to