From: <kp...@in...> - 2001-02-13 14:15:37
|
On Tue, 13 Feb 2001 08:42:59 -0300, Felipe Gomes de Carvalho wrote: >What is necessary to calculate the FPS of an application in Java, using GL4Java ? Simple version (in your code that extends GLAnimCanvas) stopFpsCounter(); int fps=(int)(getFps()); // Fractions are only theoretical. resetFpsCounter(); Extended version, draws our fps upper-right - and updates only every second: private long lastfpscount=0; private String fpstext="0 fps"; private String verticetext="0 vertices"; private String facetext="0 faces"; private void drawfps() { if (System.currentTimeMillis()-lastfpscount>1000) { stopFpsCounter(); fpstext=(int)(getFps())+" fps"; lastfpscount=System.currentTimeMillis(); resetFpsCounter(); } float xoffset=(float)global.screenwidth-100.0f; // (pixels) gl.glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_ENABLE_BIT|GL_FOG_BIT|GL_LIGHTING _BIT|GL_DEPTH_BUFFER_BIT); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity (); gl.glOrtho(0, global.screenwidth, global.screenheight, 0, -99999, 99999); gl.glDisable(GL_DEPTH_TEST); gl.glDisable(GL_TEXTURE_2D); gl.glDisable(GL_LIGHTING); gl.glColor3f(1f,1f,1f); gl.glRasterPos2f(xoffset,12.0f); glut.glutBitmapString(glut.GLUT_BITMAP_HELVETICA_10,fpstext); gl.glRasterPos2f(xoffset,26.0f); glut.glutBitmapString(glut.GLUT_BITMAP_HELVETICA_10,verticetext); gl.glRasterPos2f(xoffset,40.0f); glut.glutBitmapString(glut.GLUT_BITMAP_HELVETICA_10,facetext); gl.glPopMatrix(); gl.glMatrixMode(GL_MODELVIEW); gl.glPopMatrix(); gl.glPopAttrib(); } > > >Thanks |