-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowText.c
69 lines (57 loc) · 1.89 KB
/
ShowText.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// Created by Gabriel Mitterrutzner on 28.04.17.
//
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <stdbool.h>
int main(int argc, char ** argv)
{
bool quit = false;
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO);
TTF_Init();
SDL_Window * window = SDL_CreateWindow("SDL_ttf in SDL2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0);
TTF_Font * font = TTF_OpenFont("arial.ttf", 25);
SDL_Color color = { 255, 255, 255 };
SDL_Surface * surface = TTF_RenderText_Solid(font, "Gabriel Mitterrutzner", color);
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_Surface * surface1 = TTF_RenderText_Blended(font, "Gabriel Mitterrutzner", color);
SDL_Texture * texture1 = SDL_CreateTextureFromSurface(renderer, surface1);
int texW = 0;
int texH = 0;
SDL_QueryTexture(texture, NULL, NULL, &texW, &texH);
SDL_Rect dstrect = { 0, 0, texW, texH };
int texWi = 0;
int texHi = 0;
SDL_QueryTexture(texture1, NULL, NULL, &texWi, &texHi);
SDL_Rect dstrect1 = { 0, 25, texWi, texHi };
while (!quit)
{
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_KEYDOWN:
if (event.key.keysym.sym == 'q'){
quit = true;
}
break;
case SDL_QUIT:
quit = true;
break;
}
SDL_RenderCopy(renderer, texture, NULL, &dstrect);
SDL_RenderCopy(renderer, texture1, NULL, &dstrect1);
SDL_RenderPresent(renderer);
}
SDL_DestroyTexture(texture);
SDL_FreeSurface(surface);
SDL_DestroyTexture(texture1);
SDL_FreeSurface(surface1);
TTF_CloseFont(font);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
TTF_Quit();
SDL_Quit();
return 0;
}