• Advertisement
Sign in to follow this  

Text surface not applying (SDL)

This topic is 2473 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 am attempting to make a player's final score appear onscreen using the following render function.



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
}


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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites

The most likely candidate is either not initialising SDL_TTF correctly



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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement