这几天被CEGUI和OGRE弄的快吐血了。。。。弄的觉都没睡好。。。蛋疼。。。不过最后在哥的淫威下终于搞定了。。。特别写下这篇随笔。。把我碰到的问题和解决办法跟大家分享。。。。
1.在编译CEGUI的库的时候要把config.lua脚本的一个参数值改下首先是OGRE_PATHS和OIS_PATHS的路径设置成你OGRE的库。。。路径要写对注意格式是X:/OGRE/的格式。。。。如果编译的时候,报无法打开头文件的错可以直接在项目属性里改文件的目录找到。其次如果要把CEGUI和OGRE联用,就要把CEGUI_OLD_OIS_API变量,设置为false 找到OGRE_RENDERER变量,设置为true找到SAMPLES_OGRE变量,设置为true
2.可能你编译路径设对了但是在CEGUIOGREREND的工程里会提示无法打开一个.hpp文件。。。这里弄的最蛋疼。。。网上查说什么BOOST库编译失败。。。有说了一大堆解决方法。。。。我就在受误导弄了N久。。。悲剧呀。。。。其实很简单的在你OGRESDK下找到BOOST目录添加到你的VC++目录下就OK了。。。哎。。。。就这么简单。。。我弄了N久。。。。
3.要注意OGRESDK里的LIB是分别放在DEBUG和REALSE里的。。虽然这个解决办法很简单但是目录设错了要重新编译很麻烦。。。CEGUI的库编译起来很慢额。。。编译的让人蛋疼
4.设好编译环境就来写个简单CEGUI程序吧。。。我用DX和CEGUI创建了一个简单窗口
#include <windows.h>
#include "CEGUI.h"
#include "RendererModules\Direct3D9\CEGUIDirect3D9Renderer.h"
#include "CEGUIDefaultResourceProvider.h"
#include "CEGuiSample.h"
#include <stdio.h>
#include "d3d9.h"
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#ifdef _DEBUG
#pragma comment( lib, "CEGUIBase_d.lib" )
#pragma comment( lib, "CEGUIDirect3D9Renderer_d.lib" )
#else
#pragma comment( lib, "CEGUIBase.lib" )
#pragma comment( lib, "CEGUIDirect3D9Renderer.lib" )
#endif
using namespace CEGUI;
IDirect3D9 *g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pD3DDevice = NULL;
CEGUI::DefaultResourceProvider* rp = NULL;
HWND g_hWnd;
HINSTANCE g_hInst;
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev,
LPSTR szCmdLine, int nCmdShow);
long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
BOOL DoInit();
BOOL DoShutdown();
BOOL DoFrame();
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev,
LPSTR szCmdLine, int nCmdShow)
{
WNDCLASSEX wcex;
MSG Msg;
g_hInst = hInst;
wcex.cbSize = sizeof(wcex);
wcex.style = CS_CLASSDC;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("ShellClass");
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wcex))
return FALSE;
g_hWnd = CreateWindow(TEXT("ShellClass"),TEXT("游戏窗口"),
WS_CAPTION | WS_SYSMENU,
200, 10, 800, 600,
NULL, NULL,
hInst, NULL );
if(!g_hWnd)
return FALSE;
ShowWindow(g_hWnd, SW_NORMAL);
UpdateWindow(g_hWnd);
ZeroMemory(&Msg, sizeof(MSG));
if(DoInit() == FALSE)
return FALSE;
else
{
CEGUI::Direct3D9Renderer &myRenderer =CEGUI::Direct3D9Renderer::create(g_pD3DDevice);
CEGUI::System::create( myRenderer );
rp = static_cast<CEGUI::DefaultResourceProvider*>
(CEGUI::System::getSingleton().getResourceProvider());
rp->setResourceGroupDirectory("schemes", "../datafiles/schemes/");
rp->setResourceGroupDirectory("imagesets", "../datafiles/imagesets/");
rp->setResourceGroupDirectory("fonts", "../datafiles/fonts/");
rp->setResourceGroupDirectory("layouts", "../datafiles/layouts/");
rp->setResourceGroupDirectory("looknfeels", "../datafiles/looknfeel/");
rp->setResourceGroupDirectory("lua_scripts", "../datafiles/lua_scripts/");
rp->setResourceGroupDirectory("schemas", "../datafiles/xml_schemas/");
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( "TaharezLook.scheme" );
CEGUI::System::getSingleton().setDefaultFont( "DejaVuSans-10" );
CEGUI::System::getSingleton().setDefaultMouseCursor( "TaharezLook", "MouseArrow" );
WindowManager& wmgr = WindowManager::getSingleton();
Window* myRoot = wmgr.createWindow( "DefaultWindow", "root" );
System::getSingleton().setGUISheet( myRoot );
FrameWindow* fWnd = static_cast<FrameWindow*>(wmgr.createWindow( "TaharezLook/FrameWindow", "testWindow" ));
myRoot->addChildWindow( fWnd );
fWnd->setPosition( UVector2( UDim( 0.25f, 0 ), UDim( 0.25f, 0 ) ) );
fWnd->setSize( UVector2( UDim( 0.5f, 0 ), UDim( 0.5f, 0 ) ) );
fWnd->setText( "Hello World!" );
}
while(Msg.message != WM_QUIT)
{
if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
else
{
DoFrame();
}
}
// Run shutdown function
DoShutdown();
UnregisterClass(TEXT("ShellClass"), hInst);
return Msg.wParam;
}
long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
BOOL DoInit()
{
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE d3ddm;
if((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
return FALSE;
if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
return FALSE;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
//d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pD3DDevice)))
return FALSE;
return TRUE;
}
BOOL DoShutdown()
{
return TRUE;
}
BOOL DoFrame()
{
g_pD3DDevice->BeginScene();
g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET,D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0);
CEGUI::System::getSingleton().renderGUI();
g_pD3DDevice->EndScene();
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
return TRUE;
}
以上是一个完整代码。。。。。好的。。诡异的事开始了用红色的两句就是初始化CEGUI的关键。。如果你就这样把我的代码粘去。。。。恭喜程序提示缺少XXX.DLL。。。好的。。你满心欢喜找到DLL复制到目录下。。。满怀期待运行自己第一个CEGUI。。。但是随后弹出个WINDOWS RUNTIME 错误估计就让你满脸黑线了。。。好的。。调试发现运行到Create就内存异常了。。。一阵无语。。。是CEGUI内部运行代码。。。傻眼。。。。哎。。。我就在这卡了好久。。。好的上网查原因。。现在CEGUI新版本资料不多。。。好不容易找到解答要复制DLL。。。真是不容易呀。。。CEGUI还真是诡异额DLL也不提示下。。。
CEGUIExpatParser_d.dll,CEGUIFalagardWRBase_d.dll,CEGUISILLYImageCodec_d.dll,SILLY_d.dll。。。好的DLL加好这下应该行了吧。。。别忙。。。还要注意下资源文件的路径问题。。。就是../datafiles/... 才行。。。偶滴神呀终于跑起来了
最后给大家说下CEGUI的错误处理机制其实很强大的。。。其实前面提到的DLL未添加问题在一个CEGUI.log里都会记录。。。哎。。还是自己了解的不深呀。。。以后如果CEGUI创建问题可以去CEGUI.log找到。。。。最后感谢下曾经在CEGUI问题上帮助过我的DD们。。。额。。。人不少就不一一列出了。。。小弟在这拜谢了
另附几个资源下载网址1. ogre 1.7.0的下载地址:https://sourceforge.net/projects/ogre/files/ogre/1.7/ogre-v1-7-0.zip/download
2. ogre 1.7.0依赖库的下载地址(不定期更新,请关注该贴):http://www.ogre3d.org/forums/viewtopic.php?f=1&t=54533
3. cegui 0.7.1的下载地址:http://prdownloads.sourceforge.net/crayzedsgui/CEGUI-0.7.1.zip?download
4. cegui 0.7.1依赖库的下载地址:http://prdownloads.sourceforge.net/crayzedsgui/CEGUI-DEPS-0.7.x-r1-vc9.zip?download
——记于2010年5月6日 22::42
posted on 2010-05-06 22:44
斌子 阅读(2153)
评论(2) 编辑 收藏 引用