Archived

This topic is now archived and is closed to further replies.

Want to find the FPS on my programs

This topic is 5306 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been going through the nehe tutorials (starting #9 next) and as I was testing the finished projects I noticed that some of the features would take longer to render (duh). So I''d like to pointed towards a tutorial on how to check the fps of a OpenGL program. I thought I saw one once lying around but I can''t remember where. Do any of you know where I could find the code, and an explanation of how it works if possible?

Share this post


Link to post
Share on other sites


double getetime(bool showfps)
{
static long last = GetTickCount(); //time our last fps was displayed

static long elast = GetTickCount(); //time we last called this function, last frame

static long fps = 0; //how many frames we've counted since we displayed the fps

double etime; //the returned elapsed time since the last frame


fps++; //increment our frame counter


if (GetTickCount() - last => 1000) //if its been over 1000 ms (1 second) since our last frame display, display again

{
if (showfps) cout<<fps<<endl; //if we want to see it, show it

fps = 0; //reset counter

last = GetTickCount(); //reset last displayed time to the current time

}

etime = GetTickCount() - elast; //calculate time since we last called this function, last frame

elast = GetTickCount(); //reset our elapsed time to the current time

return etime; //return the elapsed time

}


void gameloop()
{
while(1)
{
getetime(true);
doeverthing();
}
}



Making use of the returned double will set you right up for time based animation also. Yell at me if i goofed someone.

edit: returned time since last fps update, fixed
edit2: comments

[edited by - honayboyz on June 4, 2003 1:30:51 AM]

[edited by - honayboyz on June 4, 2003 1:35:30 AM]

Share this post


Link to post
Share on other sites