What formula is used to calculate FPS in a game?

4

I'm creating a game in java using lwjgl3, I've seen many algorithms but they're all different from each other.

So simplifying my code would be like this:

start();

while(running){
    update();
    render();
}

exit();

What formula could I use to calculate fps in the game?

    
asked by anonymous 02.01.2017 / 20:14

1 answer

2

The frame rate per second (FPS or QPS) can be calculated as follows:

public void start() {
    lastFPS = getTime();
}

public void updateFPS() {
    if (getTime() - lastFPS > 1000) {
        Display.setTitle("FPS: " + fps); 
        fps = 0; //reseta o contador de FPS
        lastFPS += 1000; //adiciona um segundo
    }
    fps++;
}

The FPS representation is simple, it's how many frames were displayed in a single second. The frame rate per second is 30, which means that in one second, 30 frames were displayed.

The formula in a basic representation would be: FPS = (number of frames) / (number of seconds) . For example, if 120 seconds were displayed 6400 frames, our FPS would be ± 53,333 (6400/120).

The Display.setTitle(String title) is for simplicity, showing the counter in the window title.

More information on the documentation .

    
02.01.2017 / 20:47