Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectX font class problem!

Started by wicked357 Mar 27, 2009 at 8:53 PM 1 replies 850+ views
Original Post
wicked357
wicked357
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;
}

WOsborn
WOsborn
Did you check the result of 'bool TEXT::initFont()'???
Is it true? I don't see where you set the 'd3ddev' value.
Maybe you return false and then try and use a bad font pointer.
wicked357
wicked357
Oh... haha I can't believe I missed that, crap I am going to have to re-think some of this code a little bit. Thanks for the point out!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.