Sign in to follow this  
Followers 0
JonathanO'Brien

Text surface not applying (SDL)

2 posts in this topic

I am attempting to make a player's final score appear onscreen using the following render function.

[code]

void Endgame::render()
{
SDL_Color textColor = { 0xF0, 0xFF, 0xF0 };
//score
int totalScore = 150000 - (rectScore * 1000) - (wallScore * 2000);
//render score
std::stringstream total;
total << "Score: " << totalScore;
Score = TTF_RenderText_Solid(font, total.str().c_str(), textColor); //Score is an SDL_Surface included in the class definition.

//apply background, score
apply_surface(0, 0, background, screen, NULL);
apply_surface(50, 100, Score, screen, NULL); //The surface which refuses to apply
}
[/code]

The program builds and runs to its completion successfully in debug, but I see nothing of the "Score" surface.

Anyone who knows what I am doing wrong feel free to notify me.

Thankyou in advance.
0

Share this post


Link to post
Share on other sites
You have no error checking. If "Score" is NULL, you should log the result of TTF_GetError() somewhere to see what has gone wrong. The most likely candidate is either not initialising SDL_TTF correctly, or that your font loading failed. Unless you have error checking in these locations either to rule this out?

Also you're going to have a memory leak unless you use SDL_FreeSurface() on the text surface.
1

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1305464520' post='4811062']
The most likely candidate is either not initialising SDL_TTF correctly
[/quote]


OK, yeah, the issue was that I (for whatever reason) commented out the TTF_Init() error check earlier on in the project - which meant it wasn't initializing at all.

Thankyou.
0

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