Jump to content
  • Advertisement
Sign in to follow this  
danDemon

SDL_TTF. How to print an INT value as a text ?

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

I've spent last few hours figuring this one out. Int a = 15; TTF_RenderText_Shaded(font, "Your Score is:", foregroundColor, backgroundColor); I need to make it render "Your Score is: 15". because second parameter of TTF_RenderText_Shaded is a const char* I can't put string there (so stringstream thing won't work). I was able to make it a string, and then using str_c() cast it to const char* which won't work since the result is gonna change each time game loops. I can't use itoa() because my compiler(VC++2k8) won't let me. The typical C approach of (char*)a won't work either. Is there a way to do it ? I went to SDL_TTF documentation but couldn't find an answer there either. So right now I could either: continue trying to cast Int -> char* hope there's an easy way in SDL to print Int as a text. Any idea ?

Share this post


Link to post
Share on other sites
Advertisement
You can use std::stringstream and std::string::c_str(), you were on the right track. You just need to be able to update the text when it changes. You can write a helper class for this, something like this.

Share this post


Link to post
Share on other sites
Hey. Thanks for help. I tried both ways and somehow I made compiler buy the itoa() function. Thanks a lot. I think I'm gonna try to remake it with string streams later.

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.

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!