1

我有一个引用 *tga 纹理文件的 flt 模型。我使用 Nvidia 纹理实用工具 (nvdxt.exe) 将这些 *.tga 文件转换为 *.dds 文件。

我知道如何读取单个 .dds 纹理文件并将其应用于我的模型(terrain.flt):-

osg::ref_ptr<osg::Node> terrainModel (osgDB::readNodeFile("c:/my_folder/terrain.flt"));
osg::ref_ptr<osg::Texture2D> tex (new osg::Texture2D);
osg::ref_ptr<osg::Image> image (osgDB::readImageFile("c:/my_folder/road.dds "));

tex->setImage(image.get());

osg::ref_ptr<osg::StateSet> state=terrainModel->getOrCreateStateSet(); 

state->setTextureAttributeAndModes(0,tex.get(),osg::StateAttribute::ON);

但我不知道如何阅读所有这些纹理 *.dds 并将其应用到我的模型(terrain.flt)。

我的尝试:-

osg::ref_ptr<osg::Node> terrainModel (osgDB::readNodeFile("c:/my_folder/terrain.flt"));

osg::ref_ptr<osg::Texture2DArray> texArray (new osg::Texture2DArray);

for(int i=0;i<my_folder_files.size();i++)
{
   osg::ref_ptr<osg::Image> image (osgDB::readImageFile("c:/my_folder/"+file(i)));
   texArray->setImage(i,image);

}  

osg::ref_ptr<osg::StateSet> state=terrainModel->getOrCreateStateSet(); 

state->setTextureAttributeAndModes(0,texArray.get(),osg::StateAttribute::ON);

但是,它不起作用。帮我。

4

1 回答 1

2
osg::ref_ptr<osg::Node> terrainModel (osgDB::readNodeFile("c:/my_folder/terrain.flt"));
osg::Texture2D* texture = new osg::Texture2D;

osg::ref_ptr<osg::Image> image (osgDB::readImageFile("c:/my_folder/road.dds "));
texture->setImage(image.get());

texture->SetWrap(osg::Texture2D::WrapParameter::wrap_s,osg::Texture2D::Wrapmode::Mirror);
texture->SetWrap(osg::Texture2D::WrapParameter::wrap_t,osg::Texture2D::Wrapmode::Mirror);
texture->SetWrap(osg::Texture2D::WrapParameter::wrap_r,osg::Texture2D::Wrapmode::Mirror);

texture->setFilter(osg::texture2D::FilterParameter::MIN_FILTER,osg::Texture2D::FilterMode::LINEAR);
texture->setFilter(osg::texture2D::FilterParameter::MAG_FILTER,osg::Texture2D::FilterMode::LINEAR);

osg::material *material = new osg::material;
osg::stateset *stateset = new osg::stateset;

stateset->setTextureAttribute(0,texture,osg::stateattribute::OVERRIDE);
stateset->setTextureMode(0,GL_TEXTURE_2D,osg::stateattribute::ON|osg::stateattribute::OVERRIDE);
stateset->setTextureMode(0,GL_TEXTURE_GEN_S,osg::stateattribute::ON|osg::stateattribute::OVERRIDE);
stateset->setTextureMode(0,GL_TEXTURE_GEN_T,osg::stateattribute::ON|osg::stateattribute::OVERRIDE);
stateset->setAttribute(material,osg::stateattribute::OVERRIDE);
于 2014-04-21T09:36:02.567 回答