diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-10-16 19:36:53 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-10-16 19:46:05 +0200 |
commit | 046b2b7a38ec66208c96be59c030294b6d10351b (patch) | |
tree | 5858b113d026c47cdae0c47033eaa0bbe9f0d113 /tests | |
parent | 5cbff06ff9153f7a7958202a777d98ebeae59393 (diff) |
Add font rendering
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/main.c b/tests/main.c index 478e432..be7fcdd 100644 --- a/tests/main.c +++ b/tests/main.c @@ -4,9 +4,12 @@ #include <mgl/graphics/texture.h> #include <mgl/graphics/rectangle.h> #include <mgl/graphics/sprite.h> +#include <mgl/graphics/font.h> +#include <mgl/graphics/text.h> typedef struct { mgl_texture *texture; + mgl_font *font; } Userdata; static void draw(mgl_window *window, void *userdata) { @@ -24,6 +27,11 @@ static void draw(mgl_window *window, void *userdata) { mgl_sprite_init(&sprite, u->texture, 100.0f - 10.0f, 0.0f); mgl_sprite_set_color(&sprite, 1.0f, 1.0f, 1.0f, 0.5f); mgl_sprite_draw(context, &sprite); + + mgl_text text; + mgl_text_init(&text, u->font, "hello world!\nGood bye world!", 0.0f, 0.0f); + mgl_text_draw(context, &text); + mgl_text_deinit(&text); } int main(int argc, char **argv) { @@ -31,9 +39,11 @@ int main(int argc, char **argv) { return 1; mgl_texture texture; + mgl_font font; Userdata userdata; userdata.texture = &texture; + userdata.font = &font; mgl_window_callback window_callback; window_callback.userdata = &userdata; @@ -46,11 +56,15 @@ int main(int argc, char **argv) { if(mgl_texture_load_from_file(&texture, "X11.png", NULL) != 0) return 1; + if(mgl_font_load_from_file(&font, "/usr/share/fonts/noto/NotoSans-Regular.ttf", 32) != 0) + return 1; + for(;;) { mgl_window_events_poll(&window); mgl_window_draw(&window); } + mgl_font_unload(&font); mgl_texture_unload(&texture); mgl_window_deinit(&window); mgl_deinit(); |