0
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;

float currentTime = GetTickCount() * 0.001f;

++fps;

if(currentTime-lastTime>1.0f)
{
lastTime=currentTime;
fps=0;
}
}


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

0
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.

0
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].

0
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.

0
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

0
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.

0
101 Jul 17, 2003 at 18:23

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