#include <iostream>
#include <string.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dUtil.h>
#include <d3dApp.h>
#include <tchar.h>
#include <DxErr.h>
#include <crtdbg.h>
using namespace std;
class HelloD3DApp : public D3DApp
{
public:
HelloD3DApp(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP);
~HelloD3DApp();
bool checkDeviceCaps();
void onLostDevice();
void onResetDevice();
void updateScene(float dt);
void drawScene();
private:
ID3DXFont* mFont;
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
{
// enable runtine memory chack for debug builds
#if defined(DEBUG) | defined(_DEBUG)_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
HelloD3DApp app(hInstance, "Hello Direct3D", D3DDEVTYPE_HAL, D3DCREATE_HARDWARE_VERTEXPROCESSING);
gd3dApp = &app;
return gd3dApp->run();
}
HelloD3DApp::HelloD3DApp(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
HRESULT DXTrace(CHAR *strFile, DWORD dwline, HRESULT hr, CHAR *strMsg, BOOL bPopMsgBox);
srand(time_t(0));
if(!checkDeviceCaps())
{
MessageBox(0, "checkDeviceCaps() Failed() Failed", 0, 0);
PostQuitMessage(0);
}
D3DXFONT_DESC fontDesc;
fontDesc.Height = 80;
fontDesc.Width = 40;
fontDesc.Weight = FW_BOLD;
fontDesc.MipLevels = 0;
fontDesc.Italic = true;
fontDesc.CharSet = DEFAULT_CHARSET;
fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
fontDesc.Quality = DEFAULT_QUALITY;
fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
_tcscpy(fontDesc.FaceName, _T("Times New Roman"));
HR(D3DXCreateFontIndirect(gd3dDevice, &fontDesc, &mFont));
}
HelloD3DApp::~HelloD3DApp()
{
ReleaseCOM(mFont);
}
#define ReleaseCOM(x) {if(x) {x->Release();x = 0; } }
bool HelloD3DApp::checkDeviceCaps()
{
return true;
}
void HelloD3DApp::updateScene(float dt)
{
}
void HelloD3DApp::onLostDevice()
{
HR(mFont->OnLostDevice());
}
void HelloD3DApp::onResetDevice()
{
HR(mFont->OnResetDevice());
}
void HelloD3DApp::drawScene()
{
HR(gd3dDevice->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0F, 0));
RECT formatRect;
GetClientRect(mhMainWnd, &formatRect);
HR(gd3dDevice->BeginScene());
mFont->DrawTextA(0, _T("Hello Direct3D"), -1, &formatRect, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(rand()% 256, rand() % 256, rand() % 256));
HR(gd3dDevice->EndScene());
HR(gd3dDevice->Present(0,0,0,0,));
}
HRESULT IDirect3DDevice9::Clear(
DWORD Count, const D3DRECT* pRects,
DWORD Flags, D3DCOLOR Color,
float Z,
DWORD Stencil);
INT ID3DXFont::DrawTextA(
LPD3DXSPRITE pSprite,
LPCTSTR pString,
INT Count,
LPRECT pRect,
DWORD Format,
D3DCOLOR Color);
Quite a few issues but mostly it is the HR not recognised that is causing problems. I am using VC++ 2010 and think I have done all the linking required but what specifically is causing the HR (HRESULT?) error?