[C] Problem mit SDL_ttf

B

Bgag

Hallo!

Ich habe ein kleines Problem. ich habe heute ein kleines Ping-Pong-Spiel geschrieben, das auch relativ gut (bis auf eins - zwei Bugs) funktioniert. Leider habe ich aber noch ein Problem mit der Darstellung von Schrift mit Hilfe der SDL_ttf Bibliothek. Die Funktion, die den Text generieren und in die Bildschirmausgabe einfügen soll, findet ihr unten. Das problem ist, dass am Anfang des Programs "ThePing-Pong Game" ausgegeben werden soll, dies aber nur manchmal geschieht. Was habe ich falsch gemacht?

Danke für eure Hilfe.

MfG, Andy

C:
/* Prints out start screen.
 *
 * @param *game - game data
 */
void printWelcome(GameData *game)
{
	/* declare message font */
	TTF_Font *font;

	/* check if font could be loaded */
	if( (font = TTF_OpenFont("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-BoldItalicf", 25)) == NULL )
	{
		fprintf(stderr, "Could not load /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-BoldItalicf.");
		exit(1);
	}

	/*  init message color */
	SDL_Color green = {0x00, 0xff, 0x00, 0};

	/* init message rectangles */
	SDL_Rect rect_welcome = { SCREEN_WIDTH / 2 - 150, SCREEN_HEIGHT / 2 - 50, 300, 100 };

	/* init message holders */
	char str_welcome[32];
	SDL_Surface *text_welcome;

	/* write scoring messages */
	snprintf(str_welcome, 32, "The Ping-Pong Game");

	/* generate messages */
	text_welcome = TTF_RenderText_Solid(font, str_welcome, green);

	SDL_BlitSurface(text_welcome, NULL, game->screen, &rect_welcome);

	/* update display */
	SDL_UpdateRect(game->screen, SCREEN_WIDTH / 2 - 150, SCREEN_HEIGHT / 2 - 50, 300, 100);

	/* display welcome message for a while */
	SDL_Delay(MSG_TIME);

	/* blank the screen */
	SDL_FillRect(game->screen, NULL, 0);

	/* update display */
	SDL_Flip(game->screen);
}
 
Zurück