|
我的贴纹理的代码主要如以下:
osg::ref_ptr<osg::Texture2D> texture2d=new osg::Texture2D;
texture2d->setDataVariance(osg::Object:YNAMIC);
texture2d->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::REPEAT);
texture2d->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::REPEAT);
texture2d->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D:INEAR_MIPMAP_LINEAR);
texture2d->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
osg::ref_ptr<osg::Image> image=osgDB::readImageFile(texturePath);
if (image.valid())
{
texture2d->setImage(image.get());
}
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();
osg::ref_ptr<osg::TexEnv> te = new osg::TexEnv;
te->setMode(osg::TexEnv::REPLACE);
stateset->setTextureAttributeAndModes(0, te, osg::StateAttribute::ON|osg::StateAttribute:ROTECTED);
osg::ref_ptr<osg::TexGen> tg = new osg::TexGen;
tg->setMode(osg::TexGen::EYE_LINEAR);
stateset->setTextureAttributeAndModes(0, tg, osg::StateAttribute::ON|osg::StateAttribute::PROTECTED);
osg::ref_ptr<osg::TexMat> tm = new osg::TexMat;
stateset->setTextureAttribute(0, tm);
stateset->setTextureAttributeAndModes(0,texture2d.get(),osg::StateAttribute::ON);
stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
polygonsGeode->setStateSet(stateset.get());
其中polygonsGeode为一个Geode节点,贴完纹理后效果如下图:
效果很不佳,而原始的贴图如下:
请教高手,如何才能贴成原始贴图的清晰效果。谢谢
|
|