Skip to content

Managing and controlling the framerate

ScriptCodex13 edited this page Dec 14, 2025 · 4 revisions

We saw in the previous chapter that the window class provides a lot of functions to manage the window. Next we will talk about some more.

Managing and controlling the framerate

The FPS

In the first example we set up an init and an update part of our application. Next we will talk about the window update. Everything inside the window is drawn by the Draw() function. It is needed to calculate the delta time (or frametime) and the current FPS.

If you want to get the current FPS you can call the GetFPS() function. This returns a float of the current FPS.

float FPS = window.GetFPS();

At all Developers

As you can guess the Draw() function is needed for calculating the FPS and frametime. So if you replace the Draw() function with the native glfwSwapBuffers you can't use these functions.

Delta

Lets say our triangle moves with x += 0.1 every frame. But what if the FPS is 120 ? It runs twice as fast. But Developers found a way around that by using delta. In most cases it is just the frametime in seconds. It is then multiplied by the velocity (and a base speed) of in this example, your moving triangle. Zap does provide a function to get it. The function returns a float.

float delta = window.GetDelta();

VSync

VSync is a procedure in which the API tells the Graphics card to wait with the next frame until your monitor displayed the current frame. This can prevent Screen Tearing in which your monitor displays half of two frames each in the same moment.

to enable it you just write

window.SetVSync(true) // true(enable) or false(disable) 

Before you enable this in every project

VSync comes with the cost of a higher input lag. Which essentially means that your application is less responsive. So for a fast FPS shooter you should consider using VSync.

Clone this wiki locally