D3DXFont

Started by
2 comments, last by Squirell 20 years ago
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?
Advertisement
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
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:

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

This topic is closed to new replies.

Advertisement