Hi,
For a given texture, I want to use a specific unit texture.
But with the given example code it does not work.
When I set unitTexture = 0 it works. But when I set unitTexture =1 I have a
deep green color affected to the cylinder.
What 's wrong with my code. For me, it seems that everything is ok.
Code:
#include <osg/Geode>
#include <osg/Group>
#include <osg/ShapeDrawable>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <iostream>
osg::Node* addGeometry()
{
osg::Group* rootnode = new osg::Group;
osg::ref_ptr<osg::Cylinder> cyl = new osg::Cylinder;
cyl->setCenter(osg::Vec3(0,0,0));
cyl->setRadius(10);
cyl->setHeight(1);
osg::ref_ptr<osg::ShapeDrawable> sd = new osg::ShapeDrawable(cyl.get());
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
geode->addDrawable(sd.get());
//texture
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC);
// load Image
osg::ref_ptr<osg::Image> image = osgDB::readImageFile("grid.jpg");
if (image->valid())
{
texture->setImage(image.get());
osg::StateSet* stateset = geode->getOrCreateStateSet();
unsigned int unitTexture = 1;
stateset->setTextureAttribute(unitTexture, texture.get());
stateset->setTextureMode(unitTexture, GL_TEXTURE_2D,
osg::StateAttribute::ON);
}
rootnode->addChild(geode.get());
return rootnode;
}
int main( int argc, char **argv )
{
osg::Node* rootnode = addGeometry();
osgViewer::Viewer viewer;
// set the scene to render
viewer.setSceneData(rootnode);
return viewer.run();
}
Thank you
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=18598#18598
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org