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.
-A1P4A 0M3GA
Lead script writer on Scutum [http://www.gamedev.n...-entertainment/]
Team Member of [size=2]Forcas Entertainment
Amateur programmer with C++ and SDL knowledge
Game Enthusiast
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.
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.
-A1P4A 0M3GA
Lead script writer on Scutum [http://www.gamedev.n...-entertainment/]
Team Member of [size=2]Forcas Entertainment
Amateur programmer with C++ and SDL knowledge
Game Enthusiast