Skip to main content
gamedev.net
🔒 Locked

Text

Started by Newbie00 Jan 9, 2004 at 6:22 PM 3 replies 350+ views
Original Post
Newbie00
Newbie00
I am trying to display text onto a game surface through my d3d8.dll wrapper. Here is the code I am using.
m_pFont->DrawText( "Testing Text", 200, 120, ( 0,0,0 ) );

CFont::CFont(LPDIRECT3DDEVICE8 pD3DDevice, LPSTR pFontFace, int nHeight, bool fBold, bool fItalic, bool fUnderlined)
{
	HFONT hFont;

	m_pD3DDevice = pD3DDevice;
	
	int nWeight = FW_NORMAL;
	DWORD dwItalic = 0;
	DWORD dwUnderlined = 0;

	if(fBold)
	{
		nWeight = FW_BOLD;
	}

	if(fItalic)
	{
		dwItalic = 1;
	}

	if(fUnderlined)
	{
		dwUnderlined = 1;
	}

	hFont = CreateFont(nHeight, 0, 0, 0, nWeight, dwItalic, dwUnderlined, 0, ANSI_CHARSET, 0, 0, 0, 0, pFontFace);
	
	D3DXCreateFont(m_pD3DDevice, hFont, &m_pFont);
}

CFont::~CFont()
{
	SafeRelease(m_pFont);
}

void CFont::DrawText(LPSTR pText, int x, int y, D3DCOLOR rgbFontColour)
{
	RECT Rect;

	Rect.left = x;
	Rect.top = y;
	Rect.right = 0;
	Rect.bottom = 0;

	m_pFont->Begin();
	m_pFont->DrawTextA(pText, -1, &Rect, DT_CALCRECT, 0);			//Calculate the size of the rect needed
	m_pFont->DrawTextA(pText, -1, &Rect, DT_LEFT, rgbFontColour);	//Draw the text
	m_pFont->End();
}
 
All it does is crash the game. Does anyone have any suggestions?
RenderTarget
RenderTarget
Debugger.

That, and you should always check the return values of everything. Your program has no idea if the font or d3dxfont was successfully created.

And, debugger.


I like pie.
[sub]My spoon is too big.[/sub]
ShadowP13
ShadowP13
Use some of those debug features man! Do you know what function it''s crashing within for starters? If so, we might need to look at the function. Or perhaps what line it get''s to before locking up? The vast majority of crashes I used to get were clipping mistakes (as I used to lock the primary surface and draw on [or was it the back surface, anyway]) which also involved manually clipping my drawing requests. That''s probably not what your problem is, but if it is "Testing Text" might be too large for the screen. Try just "T".
Believe it or not, the idiot is learning.
ShadowP13
ShadowP13
He''s not really posted enough of his code for us, but I was assuming:

m_pFont->DrawTextA(pText, -1, &Rect, DT_CALCRECT, 0); //Calculate the size of the rect needed

filled the rest of the rect structure in... but then again, that might be a stupid assumption since I''ve never seen that member functions code. Otherwise, good call. Unless X and Y are negative (which would be bloody stupid) that rectange is wrong.
Believe it or not, the idiot is learning.

Topic Locked

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

Sign in to reply to this topic.