Long is a little busy these days, so he hasn't written it in recent days. Please forgive me...
Today, let's talk about a small program that longer writes with DirectX and cegui...
DX has been configured before, and the next step is to configure cegui.
PS: Dragon is vs2010, CEGUI-0.6.2-vc7
First, add the include path
Project ---> properties or press the shortcut key Alt + F7,
Add the include directory under your cegui SDK and any directory under renderermodules under the include directory (based on your rendering method ).
Then add the lib directory
Here, you only need to add the lib directory under the cegui SDK under the library directory.
As for the lib to be linked, long er prefers to use code control and won't talk about it here.
Next, let's parse the Code:
First, you must include the header file.
#include <Windows.h>#include <tchar.h>#include "CEGUI.h"#include "d3dx9.h"#include "d3d9renderer.h"#include "CEGUIDefaultResourceProvider.h"
Dragon uses the direct9 rendering method. Therefore, the previous include directory is. // renderermodules // directx9guirenderer.
Then there are some necessary global variables and the lib to be linked
#pragma comment(lib, "d3dx9.lib")#pragma comment(lib, "d3d9.lib")#pragma comment(lib, "winmm.lib")#pragma comment(lib, "CEGUIBase_d.lib")#pragma comment(lib, "DirectX9GUIRenderer_d.lib")static HWND g_hwnd;LPDIRECT3DDEVICE9 g_device;CEGUI::DirectX9Renderer* mywindow;CEGUI::DefaultResourceProvider* rp;
Like a common Windows application, it also needs to create a window first.
WNDCLASS wc;wc.cbClsExtra = 0;wc.cbWndExtra = 0;wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wc.hCursor = LoadCursor(NULL, IDC_ARROW);wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);wc.hInstance = hInstance;wc.lpfnWndProc = WndProc;wc.lpszClassName = _T("rpg");wc.lpszMenuName = NULL;wc.style = CS_VREDRAW | CS_HREDRAW;if (!RegisterClass(&wc)){return FALSE;}g_hwnd = CreateWindow(_T("rpg"), _T("rpg"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0,GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL);if (!g_hwnd){return FALSE;}UpdateWindow(g_hwnd);
Then initialize direct
LPDIRECT3D9 lpd;D3DCAPS9 caps;int vp;D3DPRESENT_PARAMETERS d3dp;lpd = Direct3DCreate9(D3D_SDK_VERSION);lpd->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);if (caps.DevCaps && D3DDEVCAPS_HWTRANSFORMANDLIGHT){vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;} else{vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;}ZeroMemory(&d3dp, sizeof(d3dp));d3dp.AutoDepthStencilFormat = D3DFMT_D24S8;d3dp.EnableAutoDepthStencil = TRUE;d3dp.Windowed = TRUE;d3dp.BackBufferFormat = D3DFMT_A8R8G8B8;d3dp.SwapEffect = D3DSWAPEFFECT_DISCARD;if (FAILED(lpd->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, vp, &d3dp, &g_device))){return FALSE;}return TRUE;
After the direct initialization, You can initialize the cegui.
mywindow = new CEGUI::DirectX9Renderer(g_device, 3000);new CEGUI::System(mywindow);rp = static_cast<CEGUI::DefaultResourceProvider*>(CEGUI::System::getSingleton().getResourceProvider());rp->setResourceGroupDirectory("fonts", "../datafiles/fonts/");rp->setResourceGroupDirectory("imagesets", "../datafiles/imagesets/");rp->setResourceGroupDirectory("layouts", "../datafiles/layouts/");rp->setResourceGroupDirectory("looknfeel", "../datafiles/looknfeel/");rp->setResourceGroupDirectory("lua_scripts", "../datafiles/lua_scripts/");rp->setResourceGroupDirectory("schemes", "../datafiles/schemes/");CEGUI::Imageset::setDefaultResourceGroup("imagesets");CEGUI::Font::setDefaultResourceGroup("fonts");CEGUI::Scheme::setDefaultResourceGroup("schemes");CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeel");CEGUI::WindowManager::setDefaultResourceGroup("layouts");CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");if (!CEGUI::FontManager::getSingleton().isFontPresent("Commonwealth-10")){CEGUI::FontManager::getSingleton().createFont("fkp-16.font");}CEGUI::SchemeManager::getSingleton().loadScheme("WindowsLook.scheme");CEGUI::System::getSingleton().setDefaultMouseCursor("WindowsLook", "MouseArrow");CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();CEGUI::Window* myroot = wmgr.createWindow("DefaultWindow", "root");CEGUI::System::getSingleton().setGUISheet(myroot);CEGUI::FrameWindow* fwnd = (CEGUI::FrameWindow*)wmgr.createWindow("WindowsLook/FrameWindow", "testWindow");myroot->addChildWindow(fwnd);fwnd->setPosition(CEGUI::UVector2(CEGUI::UDim(0.25f, 0), CEGUI::UDim(0.25f, 0)));fwnd->setSize(CEGUI::UVector2(CEGUI::UDim(0.5f, 0), CEGUI::UDim(0.5f, 0)));fwnd->setText("hello world");
Long almost forgot. If you want to use cegui, you must copy the datafiles folder in the cegui SDK sample to your current project directory. Otherwise, the necessary resources of cegui cannot be loaded.
After initialization, You can render it.
g_device->Clear(0, 0, D3DCLEAR_STENCIL | D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ffff, 1.0f, 0);g_device->BeginScene();CEGUI::System::getSingleton().renderGUI();g_device->EndScene();g_device->Present(0, 0, 0, 0);
Then you can see a very classic Hello world...
Long er is here today. I hope you can give me some advice...