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