PDA

View Full Version : fps



zauron
05-13-2002, 12:31 PM
is this a good way of finding out my fps?

if not can u point me in the right direction?




/* called duriong initialization(sp) */
bool initTimer(){
QueryPerformanceCounter (&ClockStart);
QueryPerformanceFrequency(&ClockFreq);
return true;
}

/* fps **** */
QueryPerformanceCounter(&ClockStart);
/* drawing */
DrawGLScene(); // Draw The Scene
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
/* updating logic */
logic();
/* fps **** */
QueryPerformanceCounter(&ClockFinish);
ElapsedTime = ( (double) ClockFinish.QuadPart - (double) ClockStart.QuadPart ) / ClockFreq.QuadPart;
fps = 1.0f / float(ElapsedTime);
sprintf(buffer, "Fps %f", fps);
SetWindowText(hWnd, buffer);

chowe6685
05-13-2002, 04:04 PM
you might want to check 20 frames and do
20.0f/ElapsedTime,
that way you reduce the impact of the time to call QueryPerformenceCounter and it gives you a better average for you framerate

marcus256
05-13-2002, 11:29 PM
I usually average over one second, like this:



int frames;
double t, t0;

frames = 0;
t0 = glfwGetTime();
while( 1 )
{
// Get time
t = glfwGetTime();

// Calculate and display FPS (frames per second)
if( (t-t0) > 1.0 | | frames == 0 )
{
sprintf( titlestr, "My Program (%.1f FPS)", (double)frames / (t-t0) );
glfwSetWindowTitle( titlestr );
t0 = t;
frames = 0;
}
frames ++;

// Do rest of main rendering loop...
}

glfwGetTime() returns the time in seconds as a double.



[This message has been edited by marcus256 (edited 05-14-2002).]