Adding a frames-per-second counter
The frames per second (FPS) counter is the cornerstone of all graphical application profiling and performance measurements. In this recipe, we will learn how to implement a simple FPS counter class and use it to roughly measure the performance of a running application.
Getting ready
The source code for this recipe can be found in Chapter4/GL02_FPS
.
How to do it...
Let's implement the FramesPerSecondCounter
class containing all the machinery required to calculate the average FPS rate for a given time interval:
- First, we need some member fields to store the duration of a sliding window, the number of frames rendered in the current interval, and the accumulated time of this interval:
class FramesPerSecondCounter { private: const float avgIntervalSec_ = 0.5f; unsigned int numFrames_ = 0; double accumulatedTime_ = 0; float currentFPS_ = 0.0f;
- The single constructor can override...