FPS Question...

Started by
4 comments, last by OpenGL_Guru 20 years, 5 months ago
i got my FPS displaying onto the screen.. but it keeps changing so fast i really cant tell what it says. is a usleep(someNumber) in order or what would you recommend? thanks!
heh
Advertisement
I''d just average the FPS over a certain period of time (e.g. count the number of frames in one second, every second) and output that.

- JQ
~phil
yeah, generally you average over 0.5seconds or over 1 second. i prefer the former. if you're just spitting up FPS every frame you can get widely varied values that as you've discovered make it impossible to read.

my FPS code is as follows:

//dT is passed in secondsvoid E_Engine::updateFPS(float dT) {	static int FPhalfS = 0;	static float timeCount = 0.0f;	++FPhalfS;	if ((timeCount += dT) > 0.500) {		FPS = FPhalfS / timeCount;		FPhalfS = 0;		timeCount = 0.0f;	}}


-me

[edited by - Palidine on November 12, 2003 4:38:05 PM]
this is what i have so far...(i am using WinXP)

int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
static int lasttime;
int dt;
dt=glutGet(GLUT_ELAPSED_TIME)-lasttime;
lasttime=glutGet(GLUT_ELAPSED_TIME);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

printSetup2D(frames(dt)); //prints 2D Font
glutGet(GLUT_ELAPSED_TIME);

// Reset The Current Modelview Matrix
glTranslatef(0.0, 0.0, -5.0);
glRotatef(-90, 0, 0, 1);
glRotatef(rot, 1, 0, 0);

glColor3f(0,0,1);

drawData();
etc etc

}

float frames(int LastFrameTime)
{
static int LastTimes[10]={0,0,0,0,0,0,0,0,0,0};
static int c=0;
int i;
float average=0;
c=(c+1)%10;
LastTimes[c]=LastFrameTime;

for(i=0;i<10;i++)
average+=LastTimes;
return 1000.0/(average/10.0);
}


i am getting the average here but it is still too fast. as far as i can tell i am getting 760 FPS, or something like that...

[edited by - opengl_guru on November 12, 2003 5:03:10 PM]
heh
I use an other fps counter:

long sec1 = timeGetTime();long sec2;int fpsnow = 0;int fps = 0; 


as global variable

and

sec2=timeGetTime();fps++;if(sec2-sec1>1000){  fpsnow=fps;  sec1=sec2;  fps=0;} 


every frame

it refresses the fpsnow each second

to use timeGetTime() include stdio.h and lib winmm.lib
hey thanks a lot! that works better actually that what i have. im trying to slide this into my function called inside a header file but it keeps giving me a FPS amount of 0, despite the global variables being in the main.cpp. hmmmm. anyway thanks so much!
heh

This topic is closed to new replies.

Advertisement