endo
04-01-2002, 11:56 AM
I am using this function (from gametutorials.com) to get the fps in my glut program. Can somebody tell me that it works ok because I get a constant rate of about 20, but about 40-45 when I move the paddle(It is the beginning of a breakout clone)???
It is being called immediately after the call to glutSwapBuffers().
void CalculateFrameRate()
{
static float framesPerSecond = 0.0f;
static float lastTime = 0.0f;
static char strFrameRate[50] = {0};
float currentTime = GetTickCount() * 0.001f;
// Increase the frame counter
++framesPerSecond;
if( currentTime - lastTime > 1.0f )
{
lastTime = currentTime;
cout << framesPerSecond << endl;
// Reset the frames per second
framesPerSecond = 0;
}
}
Here is the timer function in case its relevant:
void timer( int i )
{
ball.moveBall( );
glutPostRedisplay( );
glutTimerFunc( 10, timer, 1 ); //resets the timer function
}
It is being called immediately after the call to glutSwapBuffers().
void CalculateFrameRate()
{
static float framesPerSecond = 0.0f;
static float lastTime = 0.0f;
static char strFrameRate[50] = {0};
float currentTime = GetTickCount() * 0.001f;
// Increase the frame counter
++framesPerSecond;
if( currentTime - lastTime > 1.0f )
{
lastTime = currentTime;
cout << framesPerSecond << endl;
// Reset the frames per second
framesPerSecond = 0;
}
}
Here is the timer function in case its relevant:
void timer( int i )
{
ball.moveBall( );
glutPostRedisplay( );
glutTimerFunc( 10, timer, 1 ); //resets the timer function
}