Adding a frames-per-second counter
The frames-per-second (FPS) counter is the cornerstone of all graphical applications 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 our applications.
Getting ready
The source code for this recipe can be found in Chapter04/03_FPS
. The FramesPerSecondCounter
class is located in shared/UtilsFPS.h
.
How to do it...
Let’s implement the FramesPerSecondCounter
class containing all the machinery required to calculate the average FPS 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. The
printFPS_
Boolean field can be used to enable or disable FPS printing to the console:class FramesPerSecondCounter { public: float avgInterval_ = 0.5f; unsigned...