PDA

View Full Version : FPS counter


Obunako
07-14-2003, 10:18 AM
this is my FPS Counter code, but i'm not sure that is correct, what dou you think about ? something to repair ?

void FramesSecond(HWND h)
{
static float fps=0.0f,oldfps=0.0f;
* *static float lastTime=0.0f;
static char cad[30]={0};

* *float currentTime = GetTickCount() * 0.001f; * *

* *++fps;

if(currentTime-lastTime>1.0f)
*{
* * lastTime=currentTime;
*sprintf(cad,"Frames %.0f FPS",fps);
* * * *fps=0;
*}
SetWindowText (h,cad);
}

This function is called on WM_PAINT message...

case WM_PAINT:
*Render();
*FramesSecond(GetParent(hwnd));
*SwapBuffers(hdc);
*ValidateRect(hWnd,NULL);
*return 0;

And finally the paint event is called by an infinte loop into a thread...

DWORD WINAPI ThreadProcRepaint ( LPVOID lpParameter)
{
for(;;)
*{
*InvalidateRect((HWND) lpParameter, NULL, TRUE);
*UpdateWindow((HWND) lpParameter);
*}
}

thanks for all.

Dia Kharrat
07-14-2003, 04:05 PM
Does it work? The FPS calculation itself seems correct. However, I would not calculate it inside the WM_PAINT event. I would put it inside the Render() function/method.

Julio
07-14-2003, 04:19 PM
you can check out how I implimented an fps counter in my timer class. it's on my website here (http:// julio.programmers-unlimited.com).

Noor
07-14-2003, 04:26 PM
Thanks for the link it's pretty good, I suggest that you add it to devmaster.net links page! contact apex for more info.

Obunako
07-15-2003, 02:47 AM
i make this question, because, i calculate the FPS between Vertex Arrays and whitout, and de frame rates are the same. After this i said, maybe my FPS counter has a bug.

Vertex Arrays gains FPS against inmediate mode ( glVertex.. ) ?


What do you think about the Repaint thread ? :yes: :no:

Thanks all replies

Dia Kharrat
07-16-2003, 02:37 PM
You probably have VSYNC on, which will cap the framerate.
Turn it off (if its not already off) and see if it makes a change.

Obunako
07-17-2003, 12:23 PM
the vsync is not the problem, the vsync is disable :( .