Archived

This topic is now archived and is closed to further replies.

da_cobra

why can't I use "%d"

Recommended Posts

I already searched the forum for my problem and found the following solution for it : I need to pass an int into a function that takes a *char as parameter
  
HRESULT OutputText(char *pString, int x, int y, D3DCOLOR FontColor, ...) ;
   
so I did this :
  
OutputText("Framerate : %d", 0, 0, D3DCOLOR_XRGB(255, 255, 255), nFrameRate) ;
   
now I get this on my screen : Framerate : %d What did I do wrong, do I have to include a header file too if I want to use this?!? thanx in advance for any help [edited by - da_cobra on August 11, 2002 8:29:24 AM]

Share this post


Link to post
Share on other sites
"Use sprintf() to format the message before you call OutputText() "

Then why does the OutputText function have "..." as its last argument? It must be some other sort of functionality? (aside from printf style formatting). I''m curious as to what functionality that is exactly...

Share this post


Link to post
Share on other sites
ok ok I got it to work, but what I don''t understand is why it shows :

Framerate : 0

when I go in debugging mode it should display around 60

this is mu OutputText() function


  
HRESULT OutputText(char *pString, int x, int y, D3DCOLOR FontColor, ...)
{
char buffer[256] ;
va_list list ;
va_start(list, pString) ;
int ret = _vsnprintf(buffer, 256, pString, list) ;
if( ret == 256 ) buffer[255] = ''\0'' ;
va_end(list) ;

RECT FontRect = { x, y, 0, 0 } ;
HFONT hFont ;
HRESULT hr ;

hFont = (HFONT)GetStockObject(SYSTEM_FONT) ;

if(pFont)
{
pFont->Release() ;
pFont = NULL ;

}

if FAILED(D3DXCreateFont(g_lpDevice,hFont, &pFont))
{
Write2Log("Failed to Initialize font") ;
return E_FAIL ;
} // end of if


pFont->Begin() ;
pFont->DrawTextA(buffer, -1, &FontRect, DT_CALCRECT, 0) ;
hr = pFont->DrawTextA(buffer, -1, &FontRect, nAlign, FontColor) ;

pFont->End() ;
return hr ;
} // end of OutputText()

Share this post


Link to post
Share on other sites