PDA

View Full Version : FPS - Frame per Second



Leyder Dylan
07-27-2000, 06:59 AM
Hi,

Someone has a function (simple will be better) to display the FPS (frames par second) in a 3d world ?

Thanks a million

Harry of DAIW
07-27-2000, 12:06 PM
You could declare a gloab variable
int frame_counter = 0;
do frame_counter++ every frame.
ask every frame, if the standart timer says that one second passed. if yes, frame_counter is the FPS number, and you can set it = 0, and let the program continue ... :-) ...

phlake
07-27-2000, 02:10 PM
another way is if a variable timeElapsed is the number of milliseconds that have passed since your last draw, then timeElapsed/1000.0f is your fps for that precise frame. and if you're doing any animation at all, you're probably already keeping track of the time in milliseconds.

you can also keep a running average using the frame counting method and a start time. at any given point the average fps would be numFrames/((curTime - startTime)/1000.0f)

one thing to watch out for, though is that time granularity can sometimes vary, especially with winNT and 2000. glutGet(TIME_ELAPSED) can be rather innacurate on these os's. if you look at microsoft's documentation, you can increase this granularity (usually...it can return NOCANDO... i've not had it happen, but it _could_ happen).

see http://msdn.microsoft.com/library/psdk/multimed/mmfunc_2q3p.htm for microsoft doc.

Zorro
07-31-2000, 06:06 AM
Though I've been doing OpenGL and SGI-GL
applications for many years, it wasn't till
a few months ago that I decided that it
might be useful to compute and display
frame rates. This was partly due to the fact
that I started working on PCs. The answer
to your question is platform/OS specific.
In windows (I'm using NT 4.0) there's a
function called 'clock' which returns a
system time (in milliseconds?). I just
call that function each time I enter my
draw routine, store the result, subtract
off the previous result, and divide by
a constant called 'CLOCKS_PER_SEC'. That
gives me elapsed time in seconds to draw
my 3D scene once. The inverse of that is
your frame rate in units of frames per
second. I always display this in the lower
left-hand corner of my screen. I've found
it to be quite useful. I can now compare
my PC performance with performance of other
PC's with faster CPUs and 3D OpenGL boards.
I can also see how much various rendering
functions slow me down. Good luck.

Leyder Dylan
07-31-2000, 07:07 AM
Hi,

Thanks for your help !

Leyder Dylan

ngill
07-31-2000, 10:04 PM
although I know how to implement basic techniques like these. I always end up wasting CPU process time. For example If I want to wait for 30 seconds, I don't want the CPU doing cycles in a friggin while loop. Is there a better way to wait and not be wasting cpu cycles?

My guess is, that you'll (program will) have to tell the OS to send your program a message at the goal time or something... if this is really complex... just tell me, otherwise, all help would be appreciated as always!! http://www.opengl.org/discussion_boards/ubb/smile.gif