-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.c
49 lines (30 loc) · 994 Bytes
/
font.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
#include "font.h"
// initialize sdl_ttf
void decaf_font_init(void) {
TTF_Init();
}
// closes out sdl_ttf
void decaf_font_quit(void) {
TTF_Quit();
}
// loads font from given path and sets font size
TTF_Font *decaf_font_load(const char* path, int size) {
TTF_Font* font = TTF_OpenFont(path, size);
return font;
}
// frees font from memory
void decaf_font_destroy(TTF_Font* font) {
TTF_CloseFont(font);
}
// draws text with given font and color
void decaf_font_draw(TTF_Font* font, const char* text, int x, int y, decaf_color color) {
SDL_Surface* surface = TTF_RenderText_Solid(font, text, color);
SDL_Texture* texture = SDL_CreateTextureFromSurface(decaf_get_renderer(), surface);
int tex_w = 0;
int tex_h = 0;
SDL_QueryTexture(texture, NULL, NULL, &tex_w, &tex_h);
SDL_Rect rect = {x, y, tex_w, tex_h};
SDL_RenderCopy(decaf_get_renderer(), texture, NULL, &rect);
SDL_FreeSurface(surface);
SDL_DestroyTexture(texture);
}