Hey,

I created an osg::Node with osgDB::readNodeFile().
How is it possible to assign a texture to the node?

I tested it with the following code but my objet is black:

osg::ref_ptr<osg::Node> mp_node;
mp_node = osgDB::readNodeFile("cylinder.obj");
mp_node->setStateSet( getStateSet("image.Jpg") );

osg::ref_ptr<osg::StateSet> ImageViewerPlugin::getStateSet(std::string imageURL) {

        osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();
        osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
        osg::ref_ptr<osg::Image> image = osgDB::readImageFile(imageURL.c_str());
        texture->setImage(image);
        
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
        stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
        stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
        stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

        return stateset;
};

Thanks for your help,
Nils
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to