Jump to content


FPS counter


6 replies to this topic

#1 Obunako

    New Member

  • Members
  • Pip
  • 8 posts

Posted 14 July 2003 - 04:18 PM

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.

#2 Dia

    DevMaster Staff

  • Administrators
  • 1120 posts

Posted 14 July 2003 - 10: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.

#3 Julio

    New Member

  • Members
  • Pip
  • 7 posts

Posted 14 July 2003 - 10:19 PM

you can check out how I implimented an fps counter in my timer class. it's on my website here.
<a href='http://julio.programmers-unlimited.com' target='_blank'>My Crappy Homepage</a>

#4 Noor

    Senior Member

  • Members
  • PipPipPipPip
  • 503 posts

Posted 14 July 2003 - 10: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.
"What ever happened to happily ever after?"

#5 Obunako

    New Member

  • Members
  • Pip
  • 8 posts

Posted 15 July 2003 - 08: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

#6 Dia

    DevMaster Staff

  • Administrators
  • 1120 posts

Posted 16 July 2003 - 08: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.

#7 Obunako

    New Member

  • Members
  • Pip
  • 8 posts

Posted 17 July 2003 - 06:23 PM

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users