Skip to main content
GameDev.net gamedev.net
🔒 Locked

Displaying variable values with ID3DXFont

Started by sefSale Sep 4, 2006 at 10:57 AM 2 replies 700+ views
Original Post
sefSale
sefSale
I'm using ID3DXFont::DrawText to draw text on screen. Everything works fine when I'm writing strings, but how do I display variable values? I'm a bit confused because DrawText expects a pointer to the string it needs to diplay, and I want to write numbers (for example: time, points, lives...). Is there any way to convert an integer or float to a string?
Thergothon
Thergothon
use sprintf (or equivalent) to place your numbers and values into strings that can be displayed via drawtext.

ie

char buffer[32];sprintf_s(buffer, "Some value: %d", someInt);font->DrawText(0, buffer, strlen(buffer), ▭, DT_LEFT | DT_VCENTER, 0xffffffff);
mattd
mattd
Or, since you're (probably) using C++, you might as well do it right:

#include <sstream>// ...std::ostringstream os;os << "Points: " << pointsInt;font->DrawText(/* ... */, os.str().c_str(), os.str().size(), /* ... */);


Also, obligatory plug for boost::lexical_cast which may be even quicker if you already have boost available.
sefSale
sefSale
Great, thanks! It should work now...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.