diff -r 362b7659dc76 -r c5dde81b6fb2 test/sandbox.c --- a/test/sandbox.c Wed Nov 08 23:17:07 2023 +0100 +++ b/test/sandbox.c Wed Nov 15 22:51:40 2023 +0100 @@ -26,6 +26,7 @@ */ #include +#include static bool show_message_box_on_error(SDL_Window* window) { if (asc_has_error()) { @@ -50,13 +51,34 @@ AscWindow *window = asc_window_initialize(0, &settings); asc_shader_initialize_predefined(); + + AscTextNode fps_counter = {0}; + unsigned last_fps = 0; + while (asc_loop_next()) { // quit application on any error if (show_message_box_on_error(window->window)) break; + // fps counter + if (asc_context.elapsed_millis > 0) { + unsigned fps = 1000u / asc_context.elapsed_millis; + if (fps != last_fps) { + last_fps = fps; + asc_set_font(asc_font(ASC_FONT_REGULAR, 24)); + asc_ink_rgb(255, 0, 0); + cxmutstr fpstext = cx_asprintf("%u FPS", fps); + asc_text_draw(&fps_counter, (asc_vec2i) {50, 50}, fpstext); + cx_strfree(&fpstext); + } else { + asc_text_redraw(&fps_counter); + } + } } + // TODO: maybe nodes should also be "garbage collected" + asc_text_destroy(&fps_counter); + asc_context_destroy(); return 0; }