Hi, Craig Does your model have texture coordinates for tex unit 0 assigned? If not - you should generate them with texgen or use shaders to map texture correctly.
Cheers 13.10.2011, 13:23, "Craig Fletcher" <c...@hw.ac.uk>: > Hi, > > I would like to render a texture onto an .osg model that I have read in. My > code works for a primitive sphere but not the model, instead of the texture > the model colour is changed to a darker grey. Could anyone tell me what I am > doing wrong ? > > Basically i load the model which is ok I then create a geode pointer which > points to the model geode and then i set the stateset of the geode to that > containing the texture information. > > I have read something about setting texture coordinates ? i don't do anything > like this could this be my problem. > > Code below > > osg::Group *Root; > osg::Geode *mySphereGeode; > osg::ref_ptr<osg::Node> tModel; > osg::Geode* modelGeode; > > void createSphere() > { > const double sphereRadius = 0.5; > osg::Sphere* mySphere = new > osg::Sphere(osg::Vec3d(0,0,0),sphereRadius); > osg::ShapeDrawable* mySphereDrawable = new > osg::ShapeDrawable(mySphere); > mySphereGeode = new osg::Geode(); > mySphereGeode->addDrawable(mySphereDrawable); > mySphereGeode->setName("mySphere"); > osg::PositionAttitudeTransform * mySpherePAT = new > osg::PositionAttitudeTransform(); > mySpherePAT->addChild(mySphereGeode); > Root->addChild(mySpherePAT); > } > > void setTexture(osg::Geode *myGeode) > { > osg::Texture2D* texture = new osg::Texture2D; > > texture->setDataVariance(osg::Object::DYNAMIC); > texture->setFilter(osg::Texture::MIN_FILTER, > osg::Texture::LINEAR_MIPMAP_LINEAR); > texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); > texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); > texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); > > osg::Image* img = osgDB::readImageFile("drillText.tga"); > if (!img) > { > //std::cout << " couldn't find texture, quiting." << > std::endl; > //return -1; > } > > texture->setImage(img); > > osg::StateSet* stateOne = new osg::StateSet(); > > // Assign texture unit 0 of our new StateSet to the texture > // we just created and enable the texture. > stateOne->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); > > //myGeode->setStateSet(stateOne); > myGeode->setStateSet(stateOne); > > } > > void loadModel(char* name) > { > osg::ref_ptr<osg::Node> tModel = osgDB::readNodeFile(name); > osg::PositionAttitudeTransform* modelPAT = new > osg::PositionAttitudeTransform(); > tModel->setName(name); > > if(!tModel) > { > //throw std::string("Error! Could not load node file."); > //return 0; > > } > > tModel->setDataVariance( osg::Object::STATIC ); > > modelPAT->setPosition(osg::Vec3d(0, 0, 0)); > modelPAT->addChild(tModel.get()); > > Root->addChild(modelPAT); > > GeodeFinder myGeodeFinda; > Root->accept(myGeodeFinda); > modelGeode = myGeodeFinda.getGeode(name); > > } > > void main(void) > { > Root = new osg::Group(); > > //createSphere(); > //setTexture(mySphereGeode); > > loadModel("cyl60x10.osg"); > setTexture(modelGeode); > > osgViewer::Viewer viewer; > viewer.setUpViewInWindow( 50, 50, 768, 768 ); > viewer.setSceneData(Root); > > viewer.run(); > > } > > Any pointers would be greatly appreciated > > Thank you! > > Cheers, > Craig > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=43385#43385 > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org