Jump to content
  • Advertisement
Sign in to follow this  

Output Player score with D3d not workin'

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

Advertisement
Here is some code that could help.


HRESULT Font::InitFont(int sizeLogical)
{
HRESULT hRet;

RECT client = Window.getClientRect();

hRet=D3DXCreateFont(Graphics.m_pd3dDevice, //D3D Device
sizeLogical, //Font height
0, //Font width
FW_NORMAL, //Font Weight
1, //MipLevels
false, //Italic
DEFAULT_CHARSET, //CharSet
OUT_DEFAULT_PRECIS, //OutputPrecision
DEFAULT_QUALITY/*ANTIALIASED_QUALITY*/, //Quality
DEFAULT_PITCH|FF_DONTCARE,//PitchAndFamily
"Courier", //pFacename,
&g_font); //ppFont


return S_OK;
}

//HRESULT DrawText(const char *text, int xOffset=0, int yOffset=0, D3DCOLOR //color=0xFFFFFF00);
HRESULT Font::DrawText(const char *text, int xOffset, int yOffset, D3DCOLOR color)
{
RECT font_rect;
SetRect(&font_rect,xOffset,yOffset,0,0);

int font_height = g_font->DrawText(NULL, //pSprite
text, //pString
-1, //Count
&font_rect, //pRect
/*DT_LEFT|*/DT_NOCLIP,//Format,
color); //Color

return S_OK;
}



call like this:
myFont.DrawText("Hello")

Share this post


Link to post
Share on other sites
AFAIK there is a sample that uses D3DXFont in the SDK. Did you verify your code with this sample?

As a matter of fact, we won't be able to provide you a better answer unless you give us more information. What doesn't work? What are the error code (if any)? and so on...

Regards,

Share this post


Link to post
Share on other sites
yea, sorry, i should reitterate my question

basically, i know how to setup d3dxfont, but what i'm not sure on is how to pass a variable to it... in this case a player score (int format)

EDIT: I know this is a simple idea of converting an int to a string format, but it's been a while since i've done that and i don't remember how

basically i need my program to output "Player 1 Score: 10" or something where 10 is a variable in the form of an int

Sorry for wasting everyone's time on a simple question :/

Share this post


Link to post
Share on other sites
If you want to convert an int to string, there are a few options:

stringstream

stringstream ss;
ss << i;
string str = i.str(); // Not sure about the str(), I don't have documentation handy


or itoa

char buffer[33];
itoa(i, buffer, 10);


Toolmaker

Share this post


Link to post
Share on other sites
My favorite:

// Windows only
#include <stdio.h> //I think this is the right header
char buffer[256];
...
sprintf(buffer, "Player 1 score: %i", score);
myFont.DrawText( buffer );

Share this post


Link to post
Share on other sites
Quote:
Original post by CyberFox
My favorite:

// Windows only
#include <stdio.h> //I think this is the right header
char buffer[256];
...
sprintf(buffer, "Player 1 score: %i", score);
myFont.DrawText( buffer );


i get this error:

'sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA' : undeclared identifier

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!