• ogre3D学习基础18 -- 材质的使用与脚本的简单书写


    这一节以基础16为基础,练习材质的使用。

      第一,看看框架

     1 //material
     2 
     3 #include "ExampleApplication.h"
     4 
     5 class TutorialApplication : public ExampleApplication
     6 {
     7 protected:
     8 public:
     9     TutorialApplication()
    10     {
    11     }
    12 
    13     ~TutorialApplication() 
    14     {
    15     }
    16 protected:
    17     void createScene(void)
    18     {
    19 
    20     }  
    21 };
    22 
    23 
    24 #include "windows.h"
    25 
    26 INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
    27 {
    28     // Create application object
    29     TutorialApplication app;
    30     app.go();
    31     return 0;
    32 }

      第二,在createScene()里添加手动创建的对象manual

    Ogre::ManualObject *manual = mSceneMgr->createManualObject("Quad");//创建手绘对象
    manual->begin("MyMaterial",RenderOperation::OT_TRIANGLE_LIST);//这里使用的材质是material

      第三,绘制图形,正方形,并结束绘制。

       manual->position(5.0,0.0,0.0);
        manual->textureCoord(0,2);
        manual->position(-5.0,10.0,0.0);
        manual->textureCoord(2,0);
        manual->position(-5.0,0.0,0.0);
        manual->textureCoord(2,2);
        manual->position(5.0,10.0,0.0);
        manual->textureCoord(0,0);
    
        manual->index(0);//三角形一
        manual->index(1);
        manual->index(2);
    
        manual->index(0);//三角形二
        manual->index(3);
        manual->index(1);
    
        manual->end();
        manual->convertToMesh("Quad");
    
        Ogre::Entity *ent = mSceneMgr->createEntity("Quad");
        Ogre::SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node1");
        node->attachObject(ent);

      最后运行效果是一个方形白色方块。

      好,现在我们添加材质

      在路径..mediamaterialsscripts下新建一个material格式的文件,添加代码如下:

    material MyMaterial1
    {
        technique
        {
            pass
            {
                texture_unit
                {
                    texture gras_02.png
                }
            }
        }
    }

      将程序中manual->begin("MyMaterial",RenderOperation::OT_TRIANGLE_LIST);中的MyMaterial替换为MyMaterial1,效果如下:

      现在将material改为matreial2,代码如下:

    material MyMaterial2
    {
        technique
        {
            pass
            {
                texture_unit
                {
                    texture water02.jpg
                }
            }
        }
    }

      

      下面来改变一下

    manual->position(5.0, 0.0, 0.0);
    manual->textureCoord(0,2);//变为2
    manual->position(-5.0, 10.0, 0.0);
    manual->textureCoord(2,0);//变为2
    manual->position(-5.0, 0.0, 0.0);
    manual->textureCoord(2,2);//
    manual->position(5.0, 10.0, 0.0);
    manual->textureCoord(0,0);//

      看一下效果

    这样显示是系统默认的显示的方式,为 wrapping mode,内部解释为将大于2的部分复制显示,like this:

      主要是纹理问题,我们换个图片就会发现,这样的好处,你能发现区别吗,这个纹理根部看不出来是四个图片拼接而成。

      第二种纹理显示模式,称之为clamping mode,需要在脚本里添加一句话,如下:

    material MyMaterial2
    {
        technique
        {
            pass
            {
                texture_unit
                {
                    texture water02.jpg
                    tex_address_mode clamp//这句话设置显示mode
                }
            }
        }
    }

    效果很明显,四个方块,以第一个为基础,向外辐射:

      第三种类似镜子的纹理显示模式,改变脚本为

    material MyMaterial1
    {
        technique
        {
            pass
            {
                texture_unit
                {
                    texture gras_02.png
                    tex_address_mode mirror//
                }
            }
        }
    }

      效果为:

      

    镜子模式的图形分析如下:

      第四中纹理显示模式称之为border mode ,边框模式,这种模式看不出其他的明显区别,因为边框填充为黑色的

  • 相关阅读:
    编码导致 html和aspx 样式差异,变形
    Recommand of the Day:Names in English
    NSBundle常用方法及解释
    在K8S 中部署 Spring Boot 应用,爽!
    如果抛开 Spring,如何自己实现 AOP?面试必问。。。
    为什么阿里强制 boolean 类型变量不能使用 is 开头?
    CTO 说禁用 Lombok,看我怼死他。。
    面试官:什么是 YAML?和 Spring Boot 有什么关系?
    面试官:线程池多余的线程是如何回收的?
    JetBrains 发布下一代 IDE,无比轻量,几秒就能启动干活,IDEA 可以扔了。。
  • 原文地址:https://www.cnblogs.com/songliquan/p/3372365.html
Copyright © 2020-2023  润新知