FPS

This is a discussion on FPS within the Game Programming forums, part of the General Programming Boards category; Hi people, I'm wondering on how to show my FPS on the top right of my window... Can anyone tell ...

  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,893
    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,189
    Calculating the FPS:

    Code:
    DWORD TimeStart;
    DWORD TimeFinish;
    DWORD FPS;
    
    TimeStart = GetTickCount();
    
    // render code goes here
    
    TimeFinish = GetTickCount();
    
    FPS = 1000 / (TimeFinish-TimeStart);
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    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,189
    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.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

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, 03:49 PM
  4. SkyLock graphics demo (scrolling, etc.)
    By jdinger in forum Game Programming
    Replies: 9
    Last Post: 06-30-2002, 09:18 PM
  5. dramatic decrease in fps
    By DavidP in forum Game Programming
    Replies: 4
    Last Post: 06-27-2002, 10:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21