Sign in to follow this  
danDemon

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this