FPS counter

77c60eaca2812f5b7b91b03705fa64e3
0
Obunako 101 Jul 14, 2003 at 16:18

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.

6 Replies

Please log in or register to post a reply.

Fdbdc4176840d77fe6a8deca457595ab
0
dk 158 Jul 14, 2003 at 22:05

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.

7f31d4c4bf8648e1257d77609430952c
0
Julio 101 Jul 14, 2003 at 22:19

you can check out how I implimented an fps counter in my timer class. it’s on my website [URL=http:// julio.programmers-unlimited.com]here[/URL].

E05263ec846eb85da803f56e2917962d
0
Noor 101 Jul 14, 2003 at 22:26

Thanks for the link it’s pretty good, I suggest that you add it to devmaster.net links page! contact apex for more info.

77c60eaca2812f5b7b91b03705fa64e3
0
Obunako 101 Jul 15, 2003 at 08:47

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

Fdbdc4176840d77fe6a8deca457595ab
0
dk 158 Jul 16, 2003 at 20:37

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.

77c60eaca2812f5b7b91b03705fa64e3
0
Obunako 101 Jul 17, 2003 at 18:23

the vsync is not the problem, the vsync is disable :( .