50 settings.title = "Sandbox Application"; |
50 settings.title = "Sandbox Application"; |
51 |
51 |
52 AscWindow *window = asc_window_initialize(0, &settings); |
52 AscWindow *window = asc_window_initialize(0, &settings); |
53 asc_shader_initialize_predefined(); |
53 asc_shader_initialize_predefined(); |
54 |
54 |
|
55 // create fps counter and add it to the UI |
55 asc_set_font(asc_font(ASC_FONT_REGULAR, 24)); |
56 asc_set_font(asc_font(ASC_FONT_REGULAR, 24)); |
56 asc_ink_rgb(255, 0, 0); |
57 asc_ink_rgb(255, 0, 0); |
57 AscText *fps_counter = asc_text(50, 50, "9999 FPS"); |
58 AscText *fps_counter = asc_text(50, 50, "XXXXX FPS"); |
58 unsigned last_fps = 0; |
59 unsigned last_fps = 0; |
|
60 asc_scene_add(&window->ui, asc_node(fps_counter)); |
59 |
61 |
60 while (asc_loop_next()) { |
62 do { |
61 // quit application on any error |
63 // quit application on any error |
62 if (show_message_box_on_error(window->window)) break; |
64 if (show_message_box_on_error(window->window)) break; |
63 |
65 |
64 |
66 // update fps counter |
65 // fps counter |
|
66 if (asc_context.elapsed_millis > 0) { |
67 if (asc_context.elapsed_millis > 0) { |
67 unsigned fps = 1000u / asc_context.elapsed_millis; |
68 unsigned fps = 1000u / asc_context.elapsed_millis; |
68 if (fps != last_fps) { |
69 if (fps != last_fps) { |
69 last_fps = fps; |
70 last_fps = fps; |
70 snprintf(fps_counter->text, 9, "%u FPS", fps); |
71 snprintf(fps_counter->text, 9, "%u FPS", fps); |
71 asc_text_update(fps_counter); |
72 asc_text_update(fps_counter); |
72 } |
73 } |
73 } |
74 } |
74 asc_text_draw(fps_counter); |
75 } while (asc_loop_next()); |
75 } |
|
76 |
|
77 // TODO: maybe nodes should also be "garbage collected" |
|
78 asc_text_free(fps_counter); |
|
79 |
76 |
80 asc_context_destroy(); |
77 asc_context_destroy(); |
81 return 0; |
78 return 0; |
82 } |
79 } |
83 |
80 |