PDA

View Full Version : another fps question



endo
04-01-2002, 12:56 PM
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
}

chxfryer
04-01-2002, 01:27 PM
I have noticed that too with glut programs that display fps. Whenever a key is pressed, the fps jumps up as long as the key is held down. Release and the fps go back down. Not sure on what the prob with glut is

Jambolo
04-01-2002, 07:10 PM
You don't show the code that calls CalculateFrameRate. My suspicion is that it is called every time you get input in addition to every time the screen is drawn.

endo
04-02-2002, 01:14 AM
This is the code that calls CalcualteFrameRate(...). It is registered as the callback function.



void renderScene( )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f( 1.0f, 0.0f, 0.0f );

glLoadIdentity( );

ball.drawBall( );
paddle.drawPaddle( );

glutSwapBuffers( );
CalculateFrameRate( );
}

Thanks for the help http://www.opengl.org/discussion_boards/ubb/smile.gif