CEGUI 的HelloWord

下面使用CEGUI-0.7.7简述下CEGUI的初始化过程:

1.编译好CEGUI的SDK,设置好环境变量

2.创建一个win32应用程序,自己写好winmain和消息处理,嫌麻烦的可以到下面网页拷贝使用

winmain代码:http://www.cnblogs.com/gamesky/archive/2012/07/28/2612911.html

3.初始化一个IDirect3DDevice,详细过程网上多得是,我也给出一个

device初始化:http://www.cnblogs.com/gamesky/archive/2012/07/28/2612865.html

4.设置包含和依赖路径、依赖库

设置CEGUI 和DX的包含路径 :

"$(DXSDK_DIR)\Include;"..\CEGUI-0.7.7\cegui\include";"..\CEGUI-0.7.7\Samples\common\include"

设置依赖路径:

"$(DXSDK_DIR)\Lib\x86;"..\CEGUI-0.7.7\lib"

设置依赖库:

d3d9.lib
d3dx9.lib
winmm.lib
CEGUIBase_d.lib
CEGUIDirect3D9Renderer_d.lib

注意:我用了相对路径,请根据自己的实际情况修改

5.创建CEGUI的Renderer和System,设置相关资源具体代码如下:

头文件:

#include"CEGUI.h"
#include "RendererModules/Direct3D9/CEGUIDirect3D9Renderer.h"

        //创建Direct3D9Renderer,注意:bootstrapSystem中创建了system
        myRenderer= &CEGUI::Direct3D9Renderer::bootstrapSystem(pDevice);

        // bootstrapSystem与下面2句等价
        //myRenderer =&CEGUI::Direct3D9Renderer::create(pDevice);
        //CEGUI::System::create( *myRenderer );

        //设置图片解析模块setImageCodec
        CEGUI::System::getSingleton().setImageCodec("FreeImageImageCodec");

        //设置默认资源路径
        resPro = static_cast<CEGUI::DefaultResourceProvider*>
            (CEGUI::System::getSingleton().getResourceProvider());
        resPro->setResourceGroupDirectory("schemes", "../datafiles/schemes/");
        resPro->setResourceGroupDirectory("imagesets", "../datafiles/imagesets/");
        resPro->setResourceGroupDirectory("fonts", "../datafiles/fonts/");
        resPro->setResourceGroupDirectory("layouts", "../datafiles/layouts/");
        resPro->setResourceGroupDirectory("looknfeels", "../datafiles/looknfeel/");
        resPro->setResourceGroupDirectory("lua_scripts", "../datafiles/lua_scripts/");
        resPro->setResourceGroupDirectory("schemas", "../datafiles/xml_schemas/");
        resPro->setResourceGroupDirectory("animations", "../datafiles/animations/");
        CEGUI::AnimationManager::setDefaultResourceGroup("animations");
        CEGUI::Imageset::setDefaultResourceGroup("imagesets");
        CEGUI::Font::setDefaultResourceGroup("fonts");
        CEGUI::Scheme::setDefaultResourceGroup("schemes");
        CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
        CEGUI::WindowManager::setDefaultResourceGroup("layouts");
        CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");
        CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();

        if (parser->isPropertyPresent("SchemaDefaultResourceGroup"))
            parser->setProperty("SchemaDefaultResourceGroup", "schemas");

        //加载方案
        CEGUI::SchemeManager::getSingleton().create( "GuiLookSkin.scheme" );

        //设置默认字体
        CEGUI::System::getSingleton().setDefaultFont( "Serif" );

        //设置默认鼠标图标
        CEGUI::System::getSingleton().setDefaultMouseCursor( "WindowsLook", "MouseArrow" );
        WindowManager& wmgr = WindowManager::getSingleton();
        //创建跟窗口
        w_root= wmgr.createWindow( "DefaultWindow","MainRoot");
        //加载布局文件
        CEGUI::Window *pUI=wmgr.loadWindowLayout("bottomhud.layout");
        w_root->addChildWindow(pUI);
        //设置GUI的底部窗口
        System::getSingleton().setGUISheet( w_root );

6.绘制GUI,在每一帧的绘制函数中加入

CEGUI::System::getSingleton().renderGUI();
posted @ 2013-01-16 10:43  冷夜 - 网游编程技术  阅读(3280)  评论(2编辑  收藏  举报