Frame times at about 60?
Well, 75fps=13.33 msec per frame. That’s the thing I ment.
[url=http://people.freenet.de/ki_onyx/ftd.png]screenie/url
See that thing in the lower right? It displays the frame times graphically. One pixel for one msec.
It’s kinda interesting. See those rather big spikes followed by a pit? Rocksolid 75fps - despite the fact that I kinda “missed” some frames. That’s tripple buffering in action
package tools;
import org.lwjgl.Sys;
public class FrameCounter
{
private static long lastTime=0;
private static String fpsStr="";
private static long frameTime=0;
private static long lastFrameTime=0;
private static long timerRes;
private static long frameCount=0;
public FrameCounter()
{
timerRes = Sys.getTimerResolution();
}
public void tick()
{
frameCount++;
long currentTime = Sys.getTime();
frameTime = currentTime - lastFrameTime;
lastFrameTime = currentTime;
if(currentTime - lastTime > timerRes)
{
fpsStr=(int)((float)frameCount/(float)(currentTime - lastTime)*timerRes)+"fps";
frameCount=0;
lastTime=currentTime;
}
}
public String getStr()
{
return fpsStr;
}
public long getFrameTime()
{
return frameTime;
}
}
package tools;
import org.lwjgl.opengl.GL11;
public class FrameTimeDisplay
{
private final static int MAX=100;
private long[] ft;
private int ptr=0;
public FrameTimeDisplay()
{
ft=new long[MAX];
}
public void tick(long time)
{
ft[ptr]=time/1000;
++ptr;
if(ptr>=MAX)
ptr=0;
}
public void render(int xo, int yo)
{
GL11.glColor3f(0.0f,1.0f,0.0f);
GL11.glBegin(GL11.GL_LINES);
int x=xo;
for(int i=ptr;i<MAX;i++)
{
GL11.glVertex2i(x,yo);
GL11.glVertex2i(x,(int)(yo+ft[i]));
x++;
}
for(int i=0;i<ptr;i++)
{
GL11.glVertex2i(x,yo);
GL11.glVertex2i(x,(int)(yo+ft[i]));
x++;
}
GL11.glEnd();
GL11.glColor3f(1.0f,1.0f,1.0f);
}
}
logic add:
framecounter.tick();
frametimedisplay.tick(framecounter.getFrameTime());
render add (asumes default-ish 2d mode with textures disabled):
frametimedisplay.render(650,50);