|
采用一个图片对模型进行贴图,结果是正确的。程序不关,在对另外一个模型也采用图片进行贴图,显示的结果就是错的了。哪位大神清楚啊?
//创建二维纹理状态对象
osg::ref_ptr<osg::StateSet> createTexture2DState(std::string filename,int texture_unit)
{
osgDB::Options *a = NULL;
osg::ref_ptr<osg::Image> image=osgDB::readRefImageFile((filename).c_str(),a);
//创建状态集对象
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();
//创建二维纹理对象
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D();
texture->setDataVariance(osg::Object:YNAMIC);
//设置贴图
texture->setImage(image.get());
texture->setTextureWidth(image->s());
texture->setTextureHeight(image->t());
stateset->setTextureAttributeAndModes(texture_unit,texture.get(),osg::StateAttribute::ON);
osg::ref_ptr<osg::TexEnv> texenv=new osg::TexEnv;
texenv->setMode(osg::TexEnv::REPLACE);
stateset->setTextureAttributeAndModes(texture_unit,texenv.get(),osg::StateAttribute::ON);
osg::Texture::WrapMode textureWrapMode;
textureWrapMode =osg::Texture::REPEAT;
texture->setWrap(osg::Texture2D::WRAP_R, textureWrapMode);
texture->setWrap(osg::Texture2D::WRAP_S, textureWrapMode);
texture->setWrap(osg::Texture2D::WRAP_T, textureWrapMode);
stateset->setTextureAttributeAndModes( texture_unit, texture,osg::StateAttribute::ON );
return stateset.get();
}
//中函数中调用方法
osg::ref_ptr<osg::Texture2D> texture1=new osg::Texture2D;
theMesh1->setTexCoordArray(0,texcoords1.get());
theMesh1->setStateSet(createTexture2DState(imagefilepath,0));
geode1->setName(imagefilepath);
geode1->addDrawable(theMesh1);
|
-
第二次纹理错误
-
第一次纹理正确
|