Thread: FPS

  1. #1
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321

    FPS

    Hi people,
    I'm wondering on how to show my FPS on the top right of my window...
    Can anyone tell me how to do this?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    It consists of two parts.

    1) Calculating the FPS.
    2) Displaying a bit of text.

    Which of the two do you need help with?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Calculating the FPS:

    Code:
    DWORD TimeStart;
    DWORD TimeFinish;
    DWORD FPS;
    
    TimeStart = GetTickCount();
    
    // render code goes here
    
    TimeFinish = GetTickCount();
    
    FPS = 1000 / (TimeFinish-TimeStart);

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Here is how I do it.

    Code:
    int CD3DApp::EnterMsgLoop(void)
    {
      MSG msg;
      ::ZeroMemory(&msg, sizeof(MSG));
    
      static float lastTime = (float)timeGetTime(); 
      while(msg.message != WM_QUIT)
      {
        if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
        {
           ::TranslateMessage(&msg);
           ::DispatchMessage(&msg);
        }
        else
        {	
           float currTime  = (float)timeGetTime();
           float timeDelta = (currTime - lastTime)*0.001f;
           ScreenRender(timeDelta);
           lastTime = currTime;
        }
      }
        return msg.wParam;
    }
    
    void CD3DApp::CalcFPS(float timeDelta)
    {
      FrameCount++;
      TimeElapsed+=timeDelta;
    
      if (TimeElapsed>=1.0f)
      {
        FPS=(float)FrameCount/TimeElapsed;
        TimeElapsed=0.0f;
        FrameCount=0;
      }
    }
    My setup is a bit complex because this particular example is setup for cubic environment mapping and post-processing effects using PS and VS 3.0. Needless to say the timeDelta gets passed to CalcFPS() which does the frame calculation.

  5. #5
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    Thanks, but how would i display it?

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    There are probably easier ways to do it, but for something as simple as a few characters for the FPS I would just overlay some appropriate bitmaps onto your primary frame before blitting it to the screen.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SwapBuffers & fps
    By hannibar in forum Windows Programming
    Replies: 0
    Last Post: 03-13-2006, 05:19 AM
  2. Game update...
    By jdinger in forum Game Programming
    Replies: 14
    Last Post: 11-08-2002, 07:10 AM
  3. FPS Counter Prob in OpenGL
    By brandonp in forum Game Programming
    Replies: 1
    Last Post: 07-16-2002, 02:49 PM
  4. SkyLock graphics demo (scrolling, etc.)
    By jdinger in forum Game Programming
    Replies: 9
    Last Post: 06-30-2002, 08:18 PM
  5. dramatic decrease in fps
    By DavidP in forum Game Programming
    Replies: 4
    Last Post: 06-27-2002, 09:05 AM