-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
C++ Game Animation Programming - Second Edition
By :
To measure the time it takes to draw a frame, we need a stable time source. Luckily, GLFW has a function we could use for our virtual stopwatch: glfwGetTime(). This function returns the number of seconds since GLFW was initialized as a double type. The resolution of the returned value is system-dependent, but GLFW should use the time with the highest resolution. We should get the time down to micro- or nanoseconds.
We start by using GLFW as a simple timer.
To measure the time the renderer needs to draw the objects to the screen, we save the time given by glfwGetTime() at the start of the draw() method. To be able to calculate the full frame time, including the code in the Window class, we also store the starting time of the previous draw in a static variable. Then, we use a new variable in the OGLRenderData struct to transfer the difference of both time values to the UserInterface class. This difference is simply converted...