PC's JOGL Blog

Learning the Java JOGL OpenGL Bindings

Friday, June 23, 2006

What happened to my frame rate!


Ok, I don't mean to boast, but I do have a pretty good graphics card… it’s a NVidia 6800. My PC is no slouch either, and I’ve got plenty of memory, so when I started up the gears.java demo I was expecting a pretty high frame. However, it just didn’t look right. I added some code to the display() function (which gets called to display each frame) and I was getting 60FPS... Hold the phone!!!!
if(nFrame++ > 200) {
if(nLastUpdate != 0) {
long nTimeMS = System.currentTimeMillis() - nLastUpdate ;
System.out.println(nFrame + " in " + nTimeMS + "msec (" +
nFrame * 1000 / nTimeMS + " FPS)") ;
}
nFrame = 0 ;
nLastUpdate = System.currentTimeMillis() ;
}

60FPS…um… that is my monitor refresh rate (I’ve got an LCD). Ahhh, now I remember… Vertical retrace! To stop frames from tearing while being display most OpenGL implementations pause and wait for the monitors Vertical Retrace Interrupt before updating the image. Usually, it’s a pain to turn this off in OpenGL but in JOGL it’s easy. If you want to pull the maximum frame rate just set the "swap interval" to 0 in the init() function.

public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.setSwapInterval(0);

}

1100 FPS … That’s better, now that’s what I like to see!

0 Comments:

Post a Comment

<< Home