MaterialPtr material= MaterialManager::getSingleton().create("name",“ResourcesGroupName”);
material->getTechnique(0)->getPass(0)->createTextureUnitState(”TextureFilename“);
用Ogre来绘制一个立方体
ManualObject* cube;
cube = mSceneMgr->createManualObject("cube");
cube->begin("cubeMaterial");
// 顶点
cube->position( -100, -100, -100); //0
cube->colour(0.0, 0.0, 0.0);
cube->position( 100, -100, -100); //1
cube->colour(1.0, 0.0, 0.0);
cube->position( 100, -100, 100); //2
cube->colour(1.0, 0.0, 1.0);
cube->position( -100, -100, 100); //3
cube->colour(0.0, 0.0, 1.0);
cube->position( -100, 100, -100); //4
cube->colour(0.0, 1.0, 0.0);
cube->position( 100, 100, -100); //5
cube->colour(1.0, 1.0, 0.0);
cube->position( 100, 100, 100); //6
cube->colour(1.0, 1.0, 1.0);
cube->position( -100, 100, 100); //7
cube->colour(0.0, 1.0, 1.0);
//// 索引
cube->triangle(0, 2, 1);
cube->triangle(0, 2, 3);
cube->triangle(3, 4, 0);
cube->triangle(3, 7, 4);
cube->triangle(4, 7, 6);
cube->triangle(4, 6, 5);
cube->triangle(5, 2, 1);
cube->triangle(5, 6, 2);
cube->triangle(0, 4, 1);
cube->triangle(5, 1, 4);
cube->triangle(3, 6, 7);
cube->triangle(3, 2, 6);
cube->end();
SceneNode* sn = mSceneMgr->getRootSceneNode()->createChildSceneNode();
sn->attachObject(cube);
在上个立方体的基础上加上6个贴图
// 创建六个纹理
MaterialPtr material = MaterialManager::getSingletonPtr()->create("q", "General");
material->getTechnique(0)->getPass(0)->createTextureUnitState("q.jpg");
material = MaterialManager::getSingletonPtr()->create("a", "General");
material->getTechnique(0)->getPass(0)->createTextureUnitState("a.jpg");
material = MaterialManager::getSingletonPtr()->create("z", "General");
material->getTechnique(0)->getPass(0)->createTextureUnitState("z.jpg");
material = MaterialManager::getSingletonPtr()->create("x", "General");
material->getTechnique(0)->getPass(0)->createTextureUnitState("x.jpg");
material = MaterialManager::getSingletonPtr()->create("s", "General");
material->getTechnique(0)->getPass(0)->createTextureUnitState("s.jpg");
material = MaterialManager::getSingletonPtr()->create("w", "General");
material->getTechnique(0)->getPass(0)->createTextureUnitState("w.jpg");
ManualObject* cube;
cube = mSceneMgr->createManualObject("cube");
/// 下面, begin的第一个参数为要设置的材质名称
cube->begin("q", RenderOperation::OT_TRIANGLE_FAN);
cube->position( -100, -100, -100); //0
cube->textureCoord(1, 0);
cube->position( 100, -100, -100); //1
cube->textureCoord(0, 0);
cube->position( 100, -100, 100); //2
cube->textureCoord(0, 1);
cube->position( -100, -100, 100); //3
cube->textureCoord(1, 1);
cube->end();
/// 左面
cube->begin("a", RenderOperation::OT_TRIANGLE_FAN);
cube->position( -100, -100, 100); //3
cube->textureCoord(1, 0);
cube->position( -100, 100, 100); //7
cube->textureCoord(0, 0);
cube->position( -100, 100, -100); //4
cube->textureCoord(0, 1);
cube->position( -100, -100, -100); //0
cube->textureCoord(1, 1);
cube->end();
/// 上面
cube->begin("z", RenderOperation::OT_TRIANGLE_FAN);
cube->position( -100, 100, -100); //4
cube->textureCoord(1, 0);
cube->position( -100, 100, 100); //7
cube->textureCoord(0, 0);
cube->position( 100, 100, 100); //6
cube->textureCoord(0, 1);
cube->position( 100, 100, -100); //5
cube->textureCoord(1, 1);
cube->end();
/// 右面
cube->begin("x", RenderOperation::OT_TRIANGLE_FAN);
cube->position( 100, -100, -100); //1
cube->textureCoord(1, 0);
cube->position( 100, 100, -100); //5
cube->textureCoord(0, 0);
cube->position( 100, 100, 100); //6
cube->textureCoord(0, 1);
cube->position( 100, -100, 100); //2
cube->textureCoord(1, 1);
cube->end();
/// 前面
cube->begin("s", RenderOperation::OT_TRIANGLE_FAN);
cube->position( 100, -100, -100); //1
cube->textureCoord(1, 0);
cube->position( -100, -100, -100); //0
cube->textureCoord(0, 0);
cube->position( -100, 100, -100); //4
cube->textureCoord(0, 1);
cube->position( 100, 100, -100); //5
cube->textureCoord(1, 1);
cube->end();
/// 后面
cube->begin("w", RenderOperation::OT_TRIANGLE_FAN);
cube->position( 100, -100, 100); //2
cube->textureCoord(1, 0);
cube->position( 100, 100, 100); //6
cube->textureCoord(0, 0);
cube->position( -100, 100, 100); //7
cube->textureCoord(0, 1);
cube->position( -100, -100, 100); //3
cube->textureCoord(1, 1);
cube->end();