Salutare! Incerc sa fac un program care sa scrie pe ecran text D3DXFont dar nu imi apare nimic pe ecran.
Am luat codul de pe siteul asta
http://www.codesampler.com/dx9src/dx9src_5.htm#dx9_fps_controls si l-am adaptat pentru proiectul meu (deci teoretic ar trebui sa mearga, cel putin programul lor vad ca afiseaza text.
Am declarat o variabila globala in Globals.h
Cod sursă:
LPD3DXFONT g_pd3dxFont = NULL;
apoi am initializat-o cu un font in cApp::Init()
Cod sursă:
BOOL cApp::Init()
{
m_pDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
//----------------------------------------------------------
HRESULT hr;
HDC hDC;
int nHeight;
int nPointSize = 18;
hDC = GetDC( NULL );
nHeight = -( MulDiv( nPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72 ) );
ReleaseDC( NULL, hDC );
// Create a font for statistics and help output
hr = D3DXCreateFont( m_pDevice, nHeight, 0, FW_BOLD, 0, FALSE,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"),
&g_pd3dxFont );
if( FAILED( hr ) )
MessageBox(NULL,"Call to D3DXCreateFont failed!", "ERROR",MB_OK|MB_ICONEXCLAMATION);
return TRUE;
}
Asta e codul pentru eliberarea fontului la sfarsitul programului:
Cod sursă:
void cApp::ShutDown()
{
if( g_pd3dxFont != NULL )
g_pd3dxFont->Release();
}
Iar codul care afiseaza textul in fiecare frame este urmatorul
Cod sursă:
BOOL cApp::Frame()
{
m_pDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_COLORVALUE(0.0f, 0.0f, 0.0f, 1.0f), 1.0f, 0 );
RECT destRect1;
SetRect( &destRect1, 100, 100, 0, 0 );
RECT destRect2;
SetRect( &destRect2, 200, 200, 0, 0 );
RECT destRect3;
SetRect( &destRect3, 300, 300, 0, 0 );
g_pd3dxFont->DrawText( NULL,"This is a line 1.", -1, &destRect1, DT_NOCLIP,
D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f) );
g_pd3dxFont->DrawText( NULL,"This is a line 2.", -1, &destRect2, DT_NOCLIP,
D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f) );
g_pd3dxFont->DrawText( NULL,"This is a line 3.", -1, &destRect3, DT_NOCLIP,
D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f) );
return TRUE;
}
Am uploadat tot proiectul la urmatoarea adresa
http://www.fileshare.ro/8340261619.81Poate stie cineva de ce nu merge programul. Va multumesc foarte mult daca reusiti sa ii dati de capat!