Ogre动态纹理

一、材质资源

//取得该脚本材质对象

     Ogre::MaterialPtr mMaterial = MaterialManager::getSingleton().getByName("Examples/Mark");

     //根据texture索引以及pass索引删除纹理。并添加我们指定的新纹理图片

mMaterial->getTechnique(0)->getPass(0)->removeTextureUnitState(0);

     mMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("spheremap.png");

     //根据取得的材质对象,然后分别设置环境光、漫反射光;其实就是通道pass类中的成员函数

mMaterial->getTechnique(0)->getPass(0)->setAmbient(1.0, 0.0, 0.0);

     mMaterial->getTechnique(0)->getPass(0)->setDiffuse(1.0, 0.0, 0.0, 1.0);

二、纹理对象

     Ogre::TextureUnitState *texture;   

    //通过各个索引取得最后的纹理,得到该纹理对象可以通过名称,也可以通过索引值。

    texture = mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0);

//将纹理进行旋转

     texture->setTextureRotate(Ogre::Degree(30));

其实,除了可以将纹理进行旋转,我们还可以对其进行放缩、横向滚动。而且uv轴可以同时设置也可以分开设置。下面给出了其成员函数。另外还可以设置纹理边缘颜色

TextureUnitState setTextureScale(Real uScale, Real vScale);

TextureUnitState setTextureScale(Real uScale /或者 vScale);

TextureUnitState setTextureScroll(Real u, Real v);

TextureUnitState setTextureScroll(Real u /或者Real v);

TextureUnitState setTextureBorderColour(const ColourValue& colour);

猜你喜欢

转载自elviszhao.iteye.com/blog/1888815