Jump to content
  • Advertisement

Archived

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

shelagh

printing a int usiing CD3DFont->DrawText

This topic is 5808 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

Im trying to figure out how i could print an integer using the DrawText method. It only takes a char* so how do I get it to print my number? I think this is basic casting, I have: red = 123 char cRed = red g_font->DrawText(&cRed,-1,&fontRect,DT_LEFT,0xFFFFFFFF); ...but its outputting the jiberish of red, not the integer numbers.

Share this post


Link to post
Share on other sites
Advertisement
Behold the power of standard function itoa().

It is what you need.



Jacob Marner, M.Sc.
Console Programmer, Deadline Games

Share this post


Link to post
Share on other sites
I use this usefull thing:

LPCTSTR TextParam(TCHAR *szFormat, ...)
{
TCHAR szBuffer[512];

va_list pArgs;
va_start(pArgs, szFormat);
_vstprintf(szBuffer, szFormat, pArgs);
va_end(pArgs);

return szBuffer;
}

now just create your string like this:

LPCTSTR String = TextParam( TEXT("Frames p/s: %i"), FramesPS );



KaMiKaZe

Share this post


Link to post
Share on other sites
quote:
Original post by Kamikaze15
I use this usefull thing:


you''re returning address of a local variable (character array), which is illegal. the array doesn''t exist after the function returns, and sooner or later you''ll get crashes and/or memory corruptions.

Share this post


Link to post
Share on other sites
i do pretty much the same thing as kamikaze except i have the DrawText call inside the function, so nothing is ever returned and no problems ever arise.

----------------------------

hey, i know how to use DX8 now! sort of.. well i''ve got the object loading, rotation, positioning, camera, text and lights down... now for input and sound.

Share this post


Link to post
Share on other sites
quote:
Original post by niyaw

you're returning address of a local variable (character array), which is illegal. the array doesn't exist after the function returns, and sooner or later you'll get crashes and/or memory corruptions.


I know, the compiler warned me about it, but I've never found a
problem with it. I still use because it's an habit, it's a function
I wrote when I was an amateur in C++, and by that time the only thing I
did pretty well was:

#pragma warning(disable:xxxx)

lol, but I think you can use it with no problems or just do this:

TCHAR String[512];
ZeroMemory( String, 512 );
lstrcpy( String, TextParam( TEXT("Frames p/s: %i"), FramesPS ) );



KaMiKaZe

[edited by - Kamikaze15 on January 19, 2003 11:40:41 PM]

Share this post


Link to post
Share on other sites
it will bite you when you least expect it. create the array in the calling function and pass it to TextParam.

Share this post


Link to post
Share on other sites
quote:
Original post by niyaw
it will bite you when you least expect it. create the array in the calling function and pass it to TextParam.


Ok then...

void TextParam(TCHAR *OutString, TCHAR *szFormat, ...)
{
TCHAR szBuffer[512];
ZeroMemory( szBuffer, 512 );

va_list pArgs;
va_start(pArgs, szFormat);
_vstprintf(szBuffer, szFormat, pArgs);
va_end(pArgs);

lstrcpy( OutString, szBuffer );
}



KaMiKaZe

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!