We will create two new materials and one new quad. We will also change how our quad is defined:
MyMaterial11
, which we will create soon:manual->begin("MyMaterial11", RenderOperation::OT_TRIANGLE_LIST); manual->position(5.0, 0.0, 0.0); manual->textureCoord(0.0,1.0); manual->position(-5.0, 10.0, 0.0); manual->textureCoord(1.0,0.0); manual->position(-5.0, 0.0, 0.0); manual->textureCoord(1.0,1.0); manual->position(5.0, 10.0, 0.0); manual->textureCoord(0.0,0.0); manual->index(0); manual->index(1); manual->index(2); manual->index(0); manual->index(3); manual->index(1); manual->end();
rotate_anim
, which rotates the texture with the given speed. But the most important thing is to name the texture unit texture1:
material MyMaterial11 { technique { pass { texture_unit texture1 { texture terr_rock6.jpg rotate_anim 0.1 } } } }
setMaterialName()
function to change the material used by the entity to MyMaterial12:
ent = mSceneMgr->createEntity("Quad"); ent->setMaterialName("MyMaterial12");node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node2",Ogre::Vector3(15,0,0)); node->attachObject(ent);
MyMaterial12
. We will inherit from MyMaterial11
and set the texture alias to another texture that we want to use:material MyMaterial12 : MyMaterial11 { set_texture_alias texture1 Water02.jpg }
We created two quads, each with its own material. Steps 1 and 2 just modified the quad to only use texture coordinates in the range of [0,1]. In step 2, we created our material for the quad and used the new attribute rotate_anim x
, which rotates the texture x turns per second nothing fancy. Also we gave the texture unit the name texture1
; we need this name later. In step 3, we created another instance of the quad and used the setMaterialName()
function to change the material used by the entity. The important part was step 4. Here we created a new material by using inheritance, a concept which should be familiar. The syntax is the same as in C++, NewName : ParentName
. In this case, MyMaterial12
inherits from MyMaterial11
. Then we use the attribute set_texture_alias
that binds the texture Water02.jpg
to the texture unit texture1
. In this case, we replace terr_rock6.jpg
with Water02.jpg
. Because this is the only change we wanted to make with our new material, we can stop here.
The use of texture aliases enables us to create a lot of materials that only differ in the used texture without the need to write each material from the ground up, and we all know that duplication should always be avoided, if possible.
We have covered a lot of things about materials, but there is a lot more that we can do. We have covered the basics and with the help of the documentation, it should be possible to understand most of the other attributes that can be used in materials. Just take a look here http://www.ogre3d.org/docs/manual/manual_14.html#SEC23. We will now go a bit deeper and learn how to program our graphics card with the so-called shaders.
18.227.134.133