Jump to content
  • Advertisement
Sign in to follow this  
MadsGustaf

Drawing variable values to the screen with TTF and SDL

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

So, i am trying to output some variables(the players score) to the screen, but the TTF(True Type Font) doesn't have the same syntax as, when printing to the console. ex. printf("%d",score) is fine on the console. How would i do this with the TTF library?. I am currently using the TTF_RenderText_Solid function, which doesn't accept variables.

Share this post


Link to post
Share on other sites
Advertisement
I'm going to have to assume that you're using C not C++ since you're using printf(). Tell us if you are using C++.

TTF's functions take a single string to output. Luckily for you, you can format a string to have the value of a variable via a printf()-like interface. For this you use the function sprintf. It's very like printf(), but it has an s in front. Therefore, it outputs to a string, rather than the console. Once you format the string correctly, you can print it to the screen with SDL_ttf.

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!