Просмотр исходного кода

Simplify according to forum example

Luna Stadler лет назад: 4
Родитель
Сommit
6e6a671951
1 измененных файлов с 7 добавлено и 15 удалено
  1. 7 15
      c/sdl/hello_sdl.c

+ 7 - 15
c/sdl/hello_sdl.c

39
		return 1;
39
		return 1;
40
	}
40
	}
41
41
42
	char *msg = "howdy there, enby!🐘";
42
	SDL_Surface *surface = SDL_GetWindowSurface(window);
43
44
	char *msg = "howdy there, enby! 🐘";
43
45
44
	// thanks to https://stackoverflow.com/questions/22886500/how-to-render-text-in-sdl2 for some actually useful code here
46
	// thanks to https://stackoverflow.com/questions/22886500/how-to-render-text-in-sdl2 for some actually useful code here
45
	SDL_Color white = {255, 255, 255};
47
	SDL_Color white = {255, 255, 255};
46
	SDL_Color black = {0, 0, 0};
48
	SDL_Color black = {0, 0, 0};
47
	SDL_Surface* surfaceMessage = TTF_RenderUTF8_Blended(font, msg, white); 
48
	SDL_Texture* message = SDL_CreateTextureFromSurface(renderer, surfaceMessage);
49
50
	SDL_Rect text_rect;
51
	text_rect.x = 0;
52
	text_rect.y = 0;
53
	text_rect.w = surfaceMessage->w;
54
	text_rect.h = surfaceMessage->h;
49
	SDL_Surface* text = TTF_RenderUTF8_Blended(font, msg, white);
50
	SDL_BlitSurface(text, NULL, surface, NULL);
55
51
52
	// monospace -> fixed width (duh)
56
	int advance = 0;
53
	int advance = 0;
57
	for (int i = 0; i < strlen(msg); i++) {
54
	for (int i = 0; i < strlen(msg); i++) {
58
		TTF_GlyphMetrics(font, msg[i], NULL, NULL, NULL, NULL, &advance);
55
		TTF_GlyphMetrics(font, msg[i], NULL, NULL, NULL, NULL, &advance);
67
			break;
64
			break;
68
		}
65
		}
69
66
70
		SDL_RenderClear(renderer);
71
		SDL_RenderCopy(renderer, message, NULL, &text_rect);
72
		SDL_RenderPresent(renderer);
73
67
		SDL_UpdateWindowSurface(window);
74
		SDL_Delay(16);
68
		SDL_Delay(16);
75
	}
69
	}
76
70
77
	SDL_FreeSurface(surfaceMessage);
78
	SDL_DestroyTexture(message);
79
	SDL_DestroyWindow(window);
71
	SDL_DestroyWindow(window);
80
72
81
	SDL_Quit();
73
	SDL_Quit();