首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络游戏 >

关于CEGUI,编写第一个窗口的时候出错了!该如何处理

2012-03-31 
关于CEGUI,编写第一个窗口的时候出错了!#include d3d9.h#include CEGUI.h#include RendererModules\\

关于CEGUI,编写第一个窗口的时候出错了!
#include <d3d9.h>

#include "CEGUI.h"
#include "RendererModules\\Direct3D9\\CEGUIDirect3D9Renderer.h"
#include "CEGUIDefaultResourceProvider.h"


#pragma comment(lib,"CEGUIBase_d.lib")
#pragma comment(lib,"CEGUIDirect3D9Renderer_d.lib")

using namespace CEGUI;


LPDIRECT3D9 g_pD3d = NULL;
LPDIRECT3DDEVICE9 g_pD3dDevice = NULL;
LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;

struct CUSTOMVERTEX
{
float x,y,z,rhw;
DWORD color;
};

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

HRESULT InitD3d(HWND hWnd)
{
if (NULL == (g_pD3d = Direct3DCreate9(D3D_SDK_VERSION)))
{
return E_FAIL;
  
}


D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

if (FAILED(g_pD3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&g_pD3dDevice)))
{
return E_FAIL;
}

return S_OK;
}



void Cleanup()
{
if (g_pD3dDevice != NULL)
{
g_pD3dDevice->Release();
}

if (g_pD3d != NULL)
{
g_pD3d->Release();
}
}

void Render()
{
if (NULL == g_pD3dDevice)
{
return;
}

if (SUCCEEDED(g_pD3dDevice->BeginScene()))
{
g_pD3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,255),1.0f,0);

CEGUI::System::getSingleton().renderGUI();
g_pD3dDevice->EndScene();
}

g_pD3dDevice->Present(NULL,NULL,NULL,NULL);
}





LRESULT WINAPI MsgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
  Cleanup();
  PostQuitMessage(0);
  return 0;
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}


INT WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,INT)
{
WNDCLASSEX wc ={sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,
  GetModuleHandle(NULL),NULL,NULL,NULL,NULL,
L"DirectX",NULL};

RegisterClassEx(&wc);
HWND hWnd = CreateWindow(L"DirectX",L"DirectX test",WS_OVERLAPPEDWINDOW,
  0,0,800,600,GetDesktopWindow(),NULL,wc.hInstance,NULL);


if (SUCCEEDED(InitD3d(hWnd)))
{
  
  ShowWindow(hWnd,SW_SHOWDEFAULT);
  UpdateWindow(hWnd);

  MSG msg;
  ZeroMemory(&msg,sizeof(msg));


   
CEGUI::Direct3D9Renderer& myRenderer = CEGUI::Direct3D9Renderer::create(g_pD3dDevice);  

  CEGUI::System::create( myRenderer );

// initialise the required dirs for the DefaultResourceProvider
CEGUI::DefaultResourceProvider* 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/");

// This is only really needed if you are using Xerces and need to
// specify the schemas location
rp->setResourceGroupDirectory("schemas", "../datafiles/xml_schemas/");





// set the default resource groups to be used
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");

// setup default group for validation schemas
CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();
if (parser->isPropertyPresent("SchemaDefaultResourceGroup"))
parser->setProperty("SchemaDefaultResourceGroup", "schemas");

// create (load) the TaharezLook scheme file
// (this auto-loads the TaharezLook looknfeel and imageset files)
CEGUI::SchemeManager::getSingleton().create( "TaharezLook.scheme" );

// create (load) a font.
// The first font loaded automatically becomes the default font, but note
// that the scheme might have already loaded a font, so there may already
// be a default set - if we want the "Commonweath-10" font to definitely
// be the default, we should set the default explicitly afterwards.
CEGUI::FontManager::getSingleton().create( "DejaVuSans-10.font" );

System::getSingleton().setDefaultFont( "DejaVuSans-10" );
System::getSingleton().setDefaultMouseCursor( "TaharezLook", "MouseArrow" );
System::getSingleton().setDefaultTooltip( "TaharezLook/Tooltip" );

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 );

// position a quarter of the way in from the top-left of parent.
fWnd->setPosition( UVector2( UDim( 0.25f, 0 ), UDim( 0.25f, 0 ) ) );

// set size to be half the size of the parent
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
  {
  Render();
  }
  }
}
  

UnregisterClass(L"DirectX",wc.hInstance);
return 0;

}


程序编译通过

但是在执行红色部分的时候程序出错

这是什么问题呢?

请教下各位大大



[解决办法]
你可以设个断点看下
myRenderer是不是正常的值

热点排行