#### Archived

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

# D3DXFont

This topic is 5179 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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

alright thanx

##### 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
%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:

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

hope that helps if you were stuck.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 13
• 9
• 12
• 9
• ### Forum Statistics

• Total Topics
631437
• Total Posts
3000063
×