首先,在其官網下載windows版本的CEGUI-0.7.1.zip源碼壓縮包和vs編譯用的依賴庫CEGUI-DEPS-0.7.x-r1-vc71.zip(我的開發環境是vs2003,所以是vc71)。哎,干什么事情一定要細心,一不小心下了個CEGUI-DEPS-0.7.x-r1-vc9.zip ,結果編譯的時候出現了莫名其妙的錯誤,更新成了VC71的就沒問題了,可見欲速則不達的真理啊.....
下載網址:http://cegui.org.uk/api_reference/downloading.html
我遇到了點問題:運行的時候提醒我logo.png沒有加載上,莫非工作目錄不對? 去see see,所有例子的工作目錄都為空,而資源文件夾datafiles路徑是CEGUI-0.7.1\datafiles,
跟蹤程序發現CEGuiD3D9BaseApplication的構造函數中調用了DefaultResourceProvider加載資源
void CEGuiBaseApplication::initialiseResourceGroupDirectories()

{
// initialise the required dirs for the DefaultResourceProvider
CEGUI::DefaultResourceProvider* rp =
static_cast<CEGUI::DefaultResourceProvider*>
(CEGUI::System::getSingleton().getResourceProvider());
const char* dataPathPrefix = getDataPathPrefix();
char resourcePath[PATH_MAX];
// for each resource type, set a resource group directory
sprintf(resourcePath, "%s/%s", dataPathPrefix, "schemes/");
rp->setResourceGroupDirectory("schemes", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "imagesets/");
rp->setResourceGroupDirectory("imagesets", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "fonts/");
rp->setResourceGroupDirectory("fonts", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "layouts/");
rp->setResourceGroupDirectory("layouts", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "looknfeel/");
rp->setResourceGroupDirectory("looknfeels", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "lua_scripts/");
rp->setResourceGroupDirectory("lua_scripts", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "xml_schemas/");
rp->setResourceGroupDirectory("schemas", resourcePath);
}以為著不用修改所有例子程序的工作目錄,只需要將CEGUI-0.7.1\datafiles( 我這解壓后就是這個路徑 ),拷貝到CEGUI-0.7.1\projects\premake\Samples下就OK
但是執行的時候卻遇到了問題,我運行所有的CEGUI Sample全部內存錯誤,后來我跟蹤發現Window::setParent(Window* parent)函數有問題,在他的函數體內只保留d_parent = parent;transferChildSurfaces(); 這兩行內容就可以了,再編譯就一切正常了。 PS: 注釋的函數不知道有沒有潛在的錯誤
OK 編譯正常,可以運行
參照Demo寫一個簡單的例子:

int main(int /**//*argc*/, char* /**//*argv*/[]) 

{
TDemo demo;
return demo.run();
}
bool TDemo::initialiseSample()

{
using namespace CEGUI;
WindowManager& winMgr = WindowManager::getSingleton();
SchemeManager::getSingleton().create( "WindowsLook.scheme" );
//Create cursor
System::getSingleton().setDefaultMouseCursor("WindowsLook", "MouseArrow" );
//Create font
FontManager::getSingleton().create( "Girl.font" );
//Create root window
DefaultWindow* root = (DefaultWindow*)winMgr.createWindow( "WindowsLook/StaticImage", "RootWindow" );
//Set GUI root window
System::getSingleton().setGUISheet( root );
//Create child window
Window* st = winMgr.createWindow( "WindowsLook/StaticText", "StaticText" );
root->addChildWindow( st );
st->setPosition( UVector2( cegui_reldim(0.45), cegui_reldim(0.23) ) );
st->setSize( UVector2( cegui_reldim(0.15), cegui_reldim(0.05) ) );
st->setText( "Hello world" );
return true;
}
void TDemo::cleanupSample()

{
}go go go,雖然起步比較晚,但總比沒有好,加油


