Jump to content
  • Advertisement


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



This topic is 5267 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 playing around with D3DXFont. I can get text to print and all but how do i print out the value of the variable. For example i have an variable: int points. How do i print out points using D3DXFont?

Share this post

Link to post
Share on other sites
you''ll need to construct the string of text that you want to print first of all... one way of doing this is using StringStream like this...

std::ostringstream s;
s << "Score: " << points << ''\n'';

font->DrawText(sprite, s.str().c_str(), -1, &position, align, color);

oh and you ''ll need to add #include <sstream> to your includes

Mrs Kensington http://www.mikeditum.co.uk

Share this post

Link to post
Share on other sites
I had a similar problem not too long ago. the biggest problem is converting your variable to a string. I think Mrs Kensington gave the same advice to me as she/he did to me, although i had some problems with it.

i cant remember exactly what was wrong, but i seem to remember getting a error saying DrawText doesnt take 6 parameters. This is how a did mine in the end:

char strng[600]; //initialise string (600 is far too big)
sprintf(strng, "ZPOS=%f YPOS=%f XPOS=%f", zpos, ypos, xpos);

the variables zpos, ypos and xpos, will be placed in the three %f''s respectively.

Other format specifiers:

%d is integer
%x is hexadecimal
%c is character
%g is double
%f is float

%5.2f means a 5 digit number with 2 decimal places

%6d means format the integer in a field of six significant figures.

and here is my actual code for drawtext:

sprintf(strng, "YRotation=%5f", fRotationY);
g_Font->DrawText(strng, 20, &FontPosition, DT_LEFT, 0xffffffff);

hope that helps if you were stuck.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!