Original Post
I created a DirectX font class to make it easier to render text on the game window instead of typing in all the information over and over, I get 0 errors but the program bombs instantly when running. I have ran debug and can't seem to figure out what the problem is except it is on the line with font->DrawText(blah blah blah), anyone got any ideas? Here is my font header,
class TEXT
{
public:
LPD3DXFONT font; //
LPDIRECT3DDEVICE9 d3ddev;
bool initFont();
void renderFont(LPCSTR);
void positionFont(int, int, int, int);
void setFont(int, DWORD, LPCSTR);
void killFont();
private:
int Size;
DWORD Style;
LPCSTR Text;
RECT Rect;
};
void TEXT::setFont(int size, DWORD style, LPCSTR format)
{
Size = size; //Set size of font
Style = style; //Set style of font
Text = format; //Set format of font
}
bool TEXT::initFont()
{
int size = Size; //i.e. 1-XXX
DWORD style = Style; //i.e. FW_REGULAR, FW_BOLD
LPCSTR format = Text; //i.e. Arial, Times New Roman, etc...
//Create font object
if(FAILED(D3DXCreateFont(d3ddev, size, 0, style, 0, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT(format), &font)))
return false;
return true;
}
void TEXT::positionFont(int xLeft, int xRight, int yTop, int yBottom)
{
Rect.left = xLeft;
Rect.right = xRight;
Rect.top = yTop;
Rect.bottom = Rect.top + yBottom;
}
void TEXT::renderFont(LPCSTR output)
{
D3DCOLOR white = D3DCOLOR_XRGB(255, 255, 255);
font->DrawText(NULL, output, -1, &Rect, 0, white);
}
void TEXT::killFont()
{
if(font != NULL)
font->Release();
font = NULL;
}