Ogre 中加载 material方法步骤

 Ogre 中加载 material方法步骤 

1.创建一个ManualObject对象;
2.设置索引号
3.到目录../OgreSDK_vc9_v1-7-2/media/materials/scripts
新建一个material文件
Guide.material

Code:
  1. material MyMaterial1   
  2. {   
  3.     technique   
  4.     {   
  5.         pass   
  6.         {   
  7.             texture_unit  texture1   
  8.             {   
  9.                 texture terr_rock6.jpg   
  10.                 rotate_anim 0.1   
  11.             }   
  12.         }   
  13.     }   
  14. }   
  15.   
  16. material MyMaterial2 : MyMaterial1   
  17. {   
  18.     set_texture_alias texture1 Water02.jpg   
  19. }  


4,在createScene()中创建两个实体Entity
5.调用setMaterial方法

全部源代码为:

Code:
    1. #include "ExampleApplication.h"   
    2.   
    3. class Example :public ExampleApplication   
    4. {   
    5. public:   
    6.     void createScene()   
    7.     {   
    8.         Ogre::ManualObject* manual =    
    9.             mSceneMgr->createManualObject("Quad");   
    10.         manual->begin("MyMaterial1",   
    11.             RenderOperation::OT_TRIANGLE_LIST);   
    12.   
    13.         manual->position(5.0, 0.0, 0.0);   
    14.         manual->textureCoord(0,1.0);   
    15.         manual->position(-5.0, 10.0, 0.0);   
    16.         manual->textureCoord(1.0,0);   
    17.         manual->position(-5.0, 0.0,0.0);   
    18.         manual->textureCoord(1.0,1.0);   
    19.         manual->position(5.0,10.0,0.0);   
    20.         manual->textureCoord(0,0);   
    21.   
    22.         manual->index(0);   
    23.         manual->index(1);   
    24.         manual->index(2);   
    25.   
    26.         manual->index(0);   
    27.         manual->index(3);   
    28.         manual->index(1);   
    29.   
    30.         manual->end();//忽略 调用方法end()将会exception   
    31.         manual->convertToMesh("Quad");   
    32.   
    33.         Ogre::Entity* ent =mSceneMgr->createEntity("Quad");   
    34.         Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node1");   
    35.         node->attachObject(ent);   
    36.   
    37.         ent = mSceneMgr->createEntity("Quad");   
    38.         ent->setMaterialName("MyMaterial2");   
    39.         node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node2",Ogre::Vector3(15,0,0));   
    40.         node->attachObject(ent);   
    41.     }   
    42. };   
    43.   
    44.   
    45. int main(void )   
    46. {   
    47.     Example app;   
    48.     app.go();   
    49.     return 0;   
    50. }  

posted on 2014-07-23 19:06  &大飞  阅读(1191)  评论(0编辑  收藏  举报

导航