|
Post by Tyler on Sept 15, 2003 20:47:22 GMT -5
How can I make a timer to calculate the frames per second. I have tried using TickCount() but can't make it work right.
|
|
|
Post by Tom Mulgrew on Sept 16, 2003 21:15:11 GMT -5
A basic formula is: (frame drawn since last time* 1000) / (TickCount() - tick count last time) I put together a quick example: dim angle# ' Used for animation dim fps# ' Last fps reading dim prevTick ' Last tick count dim frameCount ' Frames drawn since last tick count
' Working variables dim tick, time#
' Initialise TextMode (TEXT_OVERLAID) prevTick = TickCount ()
while true ' Draw screen glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT) glLoadIdentity (): glTranslatef (0, 0, -10): glRotatef (angle#, 0, 0, 1) glBegin (GL_TRIANGLES): glVertex2f (0, 5): glVertex2f (-1, -5): glVertex2f (1, -5): glEnd () cls: print fps# DrawText () SwapBuffers () ' Update frame count and fps frameCount = frameCount + 1 if frameCount = 100 then ' Recalculate FPS after 100 frames tick = TickCount () ' Get tick count time# = (tick - prevTick) / 1000.0 ' Calculate time since last tick count reading (in seconds) if time# > 0 then fps# = frameCount / time# ' Calculate frames per second endif frameCount = 0 ' Reset frame count and tick count reading prevTick = tick endif
' Update animation while SyncTimer (10) angle# = angle# + 1 wend wend
This will recalculate the FPS every 100 frames. (Does about 350 fps on my machine.) -Tom
|
|