Hi, Pedro

Where you want show that texture?

For example, you can show that image on a square as follow, altering the
code of the file 'osgviewer.cpp':

osg::Drawable* createSquare(const osg::Vec3& corner, const osg::Vec3& width,
                            const osg::Vec3& height, osg::Image* image =
NULL)
{
    osg::Geometry* geom = new osg::Geometry;

    osg::Vec3Array* coords = new osg::Vec3Array(4);
    (*coords)[0] = corner;
    (*coords)[1] = corner+width;
    (*coords)[2] = corner+width+height;
    (*coords)[3] = corner+height;

    geom->setVertexArray(coords);

    osg::Vec3Array* norms = new osg::Vec3Array(1);
    (*norms)[0] = width^height;
    (*norms)[0].normalize();

    geom->setNormalArray(norms);
    geom->setNormalBinding(osg::Geometry::BIND_OVERALL);

    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);
    geom->setTexCoordArray(0,tcoords);

    geom->addPrimitiveSet(new
osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));

    if (image)
    {
        osg::StateSet* stateset = new osg::StateSet;
        osg::Texture2D* texture = new osg::Texture2D;
        texture->setImage(image);

stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
        geom->setStateSet(stateset);
    }

    return geom;
}

And then, in function 'main()',

osg::Vec3 corner(-25.f, 0.f, 0.f);
osg::Vec3 width(50.f, 0.f, 0.f);
osg::Vec3 height(0.f, 0.f, 50.f);
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
geode->addDrawable( createSquare(corner, width, height,
osgDB::readImageFile("porton.tif") );

viewer.setSceneData(geode.get());

I hope this help you.

Edu

PD: Please, don't attach the whole osg-users Digest :)
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to