diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-06 15:55:42 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-06 15:55:42 +0100 |
commit | cb679636f77fe2a03e8dab3a511e28e1ab898316 (patch) | |
tree | b03cada4a37a50eb50cef1e21c75c56d938868a8 /tests | |
parent | e2e7c0bf0747d55967c4be6374f3611cd96babb6 (diff) |
Fix exit being called when closing window, respond to wm ping, add is_open function to window
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/tests/main.c b/tests/main.c index d430ab2..3ead877 100644 --- a/tests/main.c +++ b/tests/main.c @@ -15,10 +15,13 @@ typedef struct { mgl_texture *texture; mgl_font *font; + mgl_font *cjk_font; mgl_vertex_buffer *vertex_buffer1; mgl_vertex_buffer *vertex_buffer2; mgl_shader_program *shader_program; mgl_clock clock; + int fps; + int fps_counter; } Userdata; static void draw(mgl_window *window, void *userdata) { @@ -41,14 +44,28 @@ static void draw(mgl_window *window, void *userdata) { mgl_sprite_draw(context, &sprite); mgl_shader_program_use(NULL); + ++u->fps_counter; + if(mgl_clock_get_elapsed_time_seconds(&u->clock) >= 1.0) { + mgl_clock_restart(&u->clock); + u->fps = u->fps_counter; + u->fps_counter = 0; + } char str[255]; - snprintf(str, sizeof(str), "Hello world!\nelapsed time: %f", mgl_clock_get_elapsed_time_seconds(&u->clock)); + snprintf(str, sizeof(str), "fps: %d", u->fps); mgl_text text; - mgl_text_init(&text, u->font, str, strlen(str), NULL); + mgl_text_init(&text, u->font, str, strlen(str)); mgl_text_draw(context, &text); mgl_text_deinit(&text); + const char *cjk_str = "一丏"; + + mgl_text cjk_text; + mgl_text_init(&cjk_text, u->cjk_font, cjk_str, strlen(cjk_str)); + mgl_text_set_position(&cjk_text, (mgl_vec2f){ 0.0f, 500.0f }); + mgl_text_draw(context, &cjk_text); + mgl_text_deinit(&cjk_text); + mgl_vertex_buffer_set_position(u->vertex_buffer1, (mgl_vec2f){ window->cursor_position.x, window->cursor_position.y }); mgl_vertex_buffer_draw(context, u->vertex_buffer1, &u->font->texture); @@ -101,6 +118,7 @@ int main(int argc, char **argv) { mgl_texture texture; mgl_font font; + mgl_font cjk_font; mgl_vertex_buffer vertex_buffer1; mgl_vertex_buffer vertex_buffer2; mgl_shader_program shader_program; @@ -108,9 +126,12 @@ int main(int argc, char **argv) { Userdata userdata; userdata.texture = &texture; userdata.font = &font; + userdata.cjk_font = &cjk_font; userdata.vertex_buffer1 = &vertex_buffer1; userdata.vertex_buffer2 = &vertex_buffer2; userdata.shader_program = &shader_program; + userdata.fps = 0; + userdata.fps_counter = 0; mgl_clock_init(&userdata.clock); mgl_window window; @@ -123,6 +144,9 @@ int main(int argc, char **argv) { if(mgl_font_load_from_file(&font, "/usr/share/fonts/noto/NotoSans-Regular.ttf", 32) != 0) return 1; + if(mgl_font_load_from_file(&cjk_font, "/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc", 32) != 0) + return 1; + if(mgl_shader_program_init(&shader_program) != 0) return 1; @@ -190,7 +214,7 @@ int main(int argc, char **argv) { fprintf(stderr, "Font texture width: %d, texture height: %d\n", font.texture.width, font.texture.height); mgl_event event; - for(;;) { + while(mgl_window_is_open(&window)) { while(mgl_window_poll_event(&window, &event)) { } |