package engine;
import java.awt.Color;
import java.awt.Font;
import com.threed.jpct.FrameBuffer;
import font.GLFont;
public class FPSCounter {
private Timer timer;
private int totalFps;
private int lastFps;
private int fps;
private GLFont font;
private final int REFRESH_TIME_IN_MILISECONDS = 1000;
public FPSCounter(){
totalFps = 0;
fps = 0;
lastFps = 0;
font = new GLFont(new Font("Arial", Font.PLAIN, 16));
timer = new Timer(REFRESH_TIME_IN_MILISECONDS);
timer.start();
}
public void addFrame(){
fps++;
if(timer.getElapsedTicks()>0) {
totalFps = (fps - lastFps);
lastFps = fps;
}
}
public void draw(FrameBuffer buffer, int x, int y){
font.blitString(buffer, "FPS: " + totalFps, x, y, 100, Color.WHITE);
}
}