[osg-users] Nodes and Textures

Nils werbung.openscenegraph.org at drego.de
Thu Nov 12 03:49:35 PST 2009



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


More information about the osg-users mailing list