Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Can not get my font rendered in DX9


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 monkeyboi   Members   -  Reputation: 188

Like
0Likes
Like

Posted 06 September 2012 - 06:35 AM

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
// Create default font
m_iFontID = LoadFont("Arial",22,false,false);
assert( m_iFontID == 0 );
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;
}
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();
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);
}
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) );
}

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

Sponsor:

#2 yewbie   Members   -  Reputation: 665

Like
0Likes
Like

Posted 07 September 2012 - 11:46 AM

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.

#3 monkeyboi   Members   -  Reputation: 188

Like
1Likes
Like

Posted 07 September 2012 - 01:15 PM

- 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.

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 Posted Image

#4 yewbie   Members   -  Reputation: 665

Like
0Likes
Like

Posted 07 September 2012 - 02:48 PM

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.

http://msdn.microsof...8(v=vs.85).aspx

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, 07 September 2012 - 02:51 PM.


#5 monkeyboi   Members   -  Reputation: 188

Like
1Likes
Like

Posted 07 September 2012 - 04:03 PM

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 : )

#6 yewbie   Members   -  Reputation: 665

Like
0Likes
Like

Posted 07 September 2012 - 05:09 PM

Thank you so much Yewbie This really help me a lot


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)

#7 monkeyboi   Members   -  Reputation: 188

Like
1Likes
Like

Posted 08 September 2012 - 05:13 AM

Cool I will do Thanks in advance




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS