Jump to content
  • Advertisement
Sign in to follow this  
AntonioR

Making a D3DXFont font class - noob problems

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

Hi,

I am trying to make a font class that usses D3DxFont to write stuff on screen. And I didn't get far.
Problem is that I don't know which type my "fontname" and "text" parameters need to be so that it can be used to call D3DX methods to set the font type and to write text.

First problem is my class with which I set the type and size of the font. I tried to send the name of the font like a std::string, but it doesn't compile. It says it cannnot convert string to CHAR.

font->setFont("Elephant",50);

void AR_Font::setFont( [enter type here] fontname, int size)
{
this->font_size = size;

D3DXFONT_DESC FontDesc={
size,
0,
400,
0,
false,
DEFAULT_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_PITCH,
fontname
};

D3DXCreateFontIndirect(g_engine->getDevice(),&FontDesc,&this->dx_font);

}


Second problem is that I don't know which type my parameters need to be to be able to read ostringstream.

I want to do this:

ostringstream blabla;
blabla<< "some text " << some_variable << " , " << other_variable << " ]";
font->write_text(blabla.str(),0,500,0xFFFF0000);



void AR_Font::write_text( [enter type here] text, double x, double y , D3DCOLOR color)
{

RECT position = {
(int)x,
(int)y,
(int)g_engine->getScreenWidth(),
(int)g_engine->getScreenHeight()
};

this->dx_font->DrawText(NULL,text,-1,&position,DT_CENTER,color);
}

Share this post


Link to post
Share on other sites
Advertisement
You want const std::string&. And then use the c_str() member function to convert it to a C-style string.

However, I'd highly recommend taking a step back and starting with something simpler than DirectX stuff until you're familiar with C++, or you're just going to keep running into problems like this.

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!