• Advertisement
Sign in to follow this  

Can not get my font rendered in DX9

This topic is 1958 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It was a whileI integrated font rendering into my program. At that moment every thing worked fine. After that I implemented other functions like memory leak detection, light, shader encapsulation ect. Couple days ago I realised the text rendering was missing. Till now I have tried all the ways I can think of but nothing could make it work. According to my back up projects, the text seems to be lost after I implementing memory leak detection. But I can not see any side effect that could cause this problem. I also track and set zbuffer, alpha, light, which change nothing in font rendering. So any idea about what could cause this problem? Thanks in advance
[CODE]
// Create default font
m_iFontID = LoadFont("Arial",22,false,false);
assert( m_iFontID == 0 );
[/CODE]
[CODE]
int MyDxRenderer::LoadFont (const char* acFace, int iSize, bool bBold,
bool bItalic)
{
// Find the first unused font location
int iLoc;
for (iLoc = 0; iLoc < m_kFontArray.GetQuantity(); iLoc++)
{
if ( !m_kFontArray[iLoc] )
break;
}
ID3DXFont* pqFont;
DWORD dwWeight = ( bBold ? FW_BOLD : FW_REGULAR );

ms_hResult = D3DXCreateFont(
m_pqDevice, // pDevice
iSize, // Height
0, // Width
dwWeight, // Weight
0, // MipLevels
(DWORD)bItalic, // Italic
DEFAULT_CHARSET, // CharSet
OUT_DEFAULT_PRECIS, // OutputPrecision
ANTIALIASED_QUALITY, // Quality
VARIABLE_PITCH, // PitchAndFamily
acFace, // pFaceName
&pqFont); // ppFont
assert( SUCCEEDED(ms_hResult) );
// Put into the font array
if ( iLoc == m_kFontArray.GetQuantity() )
m_kFontArray.Append(pqFont);
else
m_kFontArray[iLoc] = pqFont;
return iLoc;
}
[/CODE]
[CODE]
m_pkRenderer->ClearBuffers();
if ( m_pkRenderer->BeginScene() )
{
m_pkRenderer->DrawScene(m_pkScene);
DrawFont(70,70,ColourRGBA::WHITE);
/*char acMessage[256];
Vector3f temp = m_pRect->Local.GetTranslate();
sprintf_s(acMessage,256, "X = %f",temp.X());
m_pkRenderer->Draw(100,100,ColourRGBA::WHITE,acMessage);*/
m_pkRenderer->EndScene();
}
m_pkRenderer->DisplayBackBuffer();
[/CODE]
[CODE]
void MyWindowApplication::DrawFont (int iX, int iY, const ColourRGBA& rkColour){
m_iFrameCount++;
m_dCurTime = LumPySystem::GetTime();
if ((m_dCurTime-m_dPreTime)>1)
{
m_iFrame = (int)(m_iFrameCount/(m_dCurTime-m_dPreTime));
m_iFrameCount = 0;
m_dPreTime = m_dCurTime;
}
char acMessage[256];
sprintf_s(acMessage,256, "FPS: %d",m_iFrame);
m_pkRenderer->Draw(iX,iY,rkColour,acMessage);
}
[/CODE]
[CODE]
void MyDxRenderer::Draw (int iX, int iY, const ColourRGBA& rkColour,
const char* acText)
{
/*ms_hResult = m_pqDevice->SetRenderState(D3DRS_LIGHTING,FALSE);
m_pqDevice->SetRenderState(D3DRS_ZENABLE,FALSE);
ms_hResult = m_pqDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
DWORD dwFormat = D3DFVF_XYZW;
ms_hResult = m_pqDevice->SetFVF(dwFormat);*/
assert( acText );
if ( !acText )
return;
RECT kText;
kText.bottom = iY;
kText.top = iY;
kText.left = iX;
kText.right = iX;
D3DCOLOR kColour = D3DCOLOR_COLORVALUE(rkColour.R(),rkColour.G(),rkColour.B(),
rkColour.A());
ms_hResult = m_kFontArray[m_iFontID]->DrawText(
0, // pSprite
acText, // pString
-1, // Count
&kText, // pRect
DT_LEFT | DT_BOTTOM | DT_CALCRECT, // Format
kColour); // Colour
assert( SUCCEEDED(ms_hResult) );
}
[/CODE]

One thing I forgot to mention, in debug model, every function returns OK.

Share this post


Link to post
Share on other sites
Advertisement
RECT kText;
kText.bottom = iY;
kText.top = iY;
kText.left = iX;
kText.right = iX;

I few things to try:

- I know you are using DT_CALCRECT, but just try adding a width and height to your right and bottom and see if it displays.

- I would also check rkColour.A() and verify that it is not zero.

Other than that nothing really stuck out to me.

Share this post


Link to post
Share on other sites
[quote name='yewbie' timestamp='1347039973' post='4977751']
- I know you are using DT_CALCRECT, but just try adding a width and height to your right and bottom and see if it displays.
[/quote]
Thanks yewbie I get it solved by using
kText.bottom = iY+100;
kText.top = iY;
kText.left = iX;
kText.right = iX+100;

ms_hResult = m_kFontArray[m_iFontID]->DrawText(
0, // pSprite
acText, // pString
-1, // Count
&kText, // pRect
DT_LEFT | DT_BOTTOM , // Format | DT_CALCRECT
kColour);

Really want to know what is the problem of the previous one [img]http://public.gamedev.net//public/style_emoticons/default/huh.png[/img]

Share this post


Link to post
Share on other sites
[quote]Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If the largest word is wider than the rectangle, the width is expanded. If the text is less than the width of the rectangle, the width is reduced. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.[/quote]
[url="http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498%28v=vs.85%29.aspx"]http://msdn.microsof...8(v=vs.85).aspx[/url]

Ah i forgot using DT_CALCRECT will return the calculated rect but not actually draw anything!

edit: thats not actually the same function you are using but it works the same Edited by yewbie

Share this post


Link to post
Share on other sites
Thank you so much Yewbie This really help me a lot
Yeah I have seen the link. It looks like DrawText is a function embeded in windows development. Reckon the function in DirectX works in the same way coz it is by microsoft as well : )

Share this post


Link to post
Share on other sites
[quote name='monkeyboi' timestamp='1347055412' post='4977829']
Thank you so much Yewbie This really help me a lot
[/quote]

No problem, I did a ton of work for directx9 a year or two ago so if you have any questions feel free to PM me (Although I don't check GD every day)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement