Sign in to follow this  

Drawing variable values to the screen with TTF and SDL

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

This topic is 3661 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.

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