From 3b2e96e0b1eeca47e9ed1df76e6c50d00b8b6538 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 Mar 2016 12:33:26 +0100 Subject: [PATCH] Improve cursor test animation Only set cursor when it's time for a new frame. Use glfwWaitEventsTimeout when waiting for events during animation. --- tests/cursor.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/cursor.c b/tests/cursor.c index cbd5f0ee..f1bcc42f 100644 --- a/tests/cursor.c +++ b/tests/cursor.c @@ -195,6 +195,7 @@ int main(void) int i; GLFWwindow* window; GLFWcursor* star_cursors[CURSOR_FRAME_COUNT]; + GLFWcursor* current_frame = NULL; glfwSetErrorCallback(error_callback); @@ -279,11 +280,22 @@ int main(void) if (animate_cursor) { const int i = (int) (glfwGetTime() * 30.0) % CURSOR_FRAME_COUNT; - glfwSetCursor(window, star_cursors[i]); + if (current_frame != star_cursors[i]) + { + glfwSetCursor(window, star_cursors[i]); + current_frame = star_cursors[i]; + } } + else + current_frame = NULL; if (wait_events) - glfwWaitEvents(); + { + if (animate_cursor) + glfwWaitEventsTimeout(1.0 / 30.0); + else + glfwWaitEvents(); + } else glfwPollEvents();