I have used ID3DXFont before but it was before I used this new code base and now I can't get it to work. All the font creation and drawing calls are working and I just can't see what's wrong.
WinMain
Code:
/* Globals */
const UINT g_iWidth = 1024;
const UINT g_iHeight = 768;
HWND g_hWnd;
const char szClassName[ ] = "DirectX App";
IDirect3D9 *g_pD3D;
IDirect3DDevice9 *g_pDevice;
d3d App;
ID3DXFont *font = 0;
char *font_name = "Times New Roman";
int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil){
MSG msg;
::ZeroMemory(&msg,sizeof(MSG));
if(!InitWindow(g_iWidth,g_iHeight,hThisInstance,nFunsterStil)){
::MessageBox(0, "InitWindow() - FAILED", 0, 0);
}
if(!App.InitD3D(g_hWnd, g_iWidth, g_iHeight, true, D3DDEVTYPE_HAL, &g_pD3D, &g_pDevice)){
::MessageBox(0, "InitD3D() - FAILED", 0, 0);
return 0;
}
Setup();
App.EnterMsgLoop(Display,msg);
Cleanup();
return msg.wParam;
}
Setup
Code:
bool Setup(){
D3DXCreateFont(g_pDevice,
22,
0,
FW_NORMAL,
1,
false,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,
"Arial",
&font);
return true;
}
Display
Code:
bool Display(float timeDelta){
RECT rect;
SetRect(&rect,0,0,640,480);
g_pDevice->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,0x77777777,1.0f,0);
g_pDevice->BeginScene();
font->DrawText(NULL,"Hello World!",-1,&rect,DT_LEFT|DT_NOCLIP,0x00000000);
g_pDevice->EndScene();
g_pDevice->Present(0,0,0,0);
return true;
}
You probably don't ned to see this one but I'll show it just incase
d3d::InitD3D
Code:
bool d3d::InitD3D(HWND hWnd, int width, int height, bool windowed,
D3DDEVTYPE deviceType, IDirect3D9 **D3D, IDirect3DDevice9 **device){
*D3D = Direct3DCreate9( D3D_SDK_VERSION );
if(!(*D3D)){
return false;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.BackBufferWidth = width;
d3dpp.BackBufferHeight = height;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.Windowed = windowed;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
if(FAILED((*D3D)->CreateDevice(D3DADAPTER_DEFAULT, deviceType, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp, device))){
(*D3D)->Release();
D3D = NULL;
return false;
}
return true;
}