Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. CLR,How do I calculate FPS

CLR,How do I calculate FPS

Scheduled Pinned Locked Moved Managed C++/CLI
c++questiondotnetdata-structurestutorial
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    akira32
    wrote on last edited by
    #1

    I use Application::Idle to calculate FPS, but it seems to be unsuitable. Becuase the Application::Idle does not like the CWinApp::Idle in MFC. Application::Idle event is not called in every frame. Could somebody know how to calculate FPS in Visual C++ CLR project?

    [STAThreadAttribute]
    int main(array<System::String ^> ^args)
    {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);

    Form1^ form1=gcnew Form1();
    Application::Idle += gcnew System::EventHandler(form1,&Form1::Form1_Idle);
    Application::Run(form1);
    return 0;
    }

    public: System::Void Form1_Idle(System::Object^ sender, System::EventArgs^ e)
    {
    DWORD currentTime=GetTickCount();
    DWORD deltaTime=currentTime-m_PlayCurrentTime;

    m\_PlayCurrentTime=currentTime;
    
    m\_FPS->FrameCnt++;
    m\_FPS->TimeElapsed+=deltaTime;
    
    if (m\_FPS->TimeElapsed >= 1000)
    {
     m\_FPS->CalculateFPS();
     m\_FPS->TimeElapsed -= 1000;
     m\_FPS->FrameCnt    = 0;
     FPStoolStripStatusLabel->Text=L"FPS=" + m\_FPS->dFPS.ToString(); 
    }       
    

    }

    M 1 Reply Last reply
    0
    • A akira32

      I use Application::Idle to calculate FPS, but it seems to be unsuitable. Becuase the Application::Idle does not like the CWinApp::Idle in MFC. Application::Idle event is not called in every frame. Could somebody know how to calculate FPS in Visual C++ CLR project?

      [STAThreadAttribute]
      int main(array<System::String ^> ^args)
      {
      Application::EnableVisualStyles();
      Application::SetCompatibleTextRenderingDefault(false);

      Form1^ form1=gcnew Form1();
      Application::Idle += gcnew System::EventHandler(form1,&Form1::Form1_Idle);
      Application::Run(form1);
      return 0;
      }

      public: System::Void Form1_Idle(System::Object^ sender, System::EventArgs^ e)
      {
      DWORD currentTime=GetTickCount();
      DWORD deltaTime=currentTime-m_PlayCurrentTime;

      m\_PlayCurrentTime=currentTime;
      
      m\_FPS->FrameCnt++;
      m\_FPS->TimeElapsed+=deltaTime;
      
      if (m\_FPS->TimeElapsed >= 1000)
      {
       m\_FPS->CalculateFPS();
       m\_FPS->TimeElapsed -= 1000;
       m\_FPS->FrameCnt    = 0;
       FPStoolStripStatusLabel->Text=L"FPS=" + m\_FPS->dFPS.ToString(); 
      }       
      

      }

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      akira32 wrote:

      Could somebody know how to calculate FPS in Visual C++ CLR

      FPS of what? What frames?

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      A 1 Reply Last reply
      0
      • M Mark Salsbery

        akira32 wrote:

        Could somebody know how to calculate FPS in Visual C++ CLR

        FPS of what? What frames?

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        A Offline
        A Offline
        akira32
        wrote on last edited by
        #3

        FPS is frame per second. Sorry! m_FPS is customized strcut as below: ref struct sFPS { sFPS() { Init(); } void Init() { FrameCnt=0; TimeElapsed=0; dFPS=0; } void CalculateFPS() { dFPS = (Double)FrameCnt / (TimeElapsed/1000.0f); } DWORD FrameCnt; DWORD TimeElapsed; Double dFPS; }; In MFC project, I can use the CWinApp::Idle to count the frame number for FPS. But in CLR project. Application::Idle is not always called(must have some windows messages be triggerred), so I cannot use it to calculate FPS if the mouse does not focus on the winform. I want to find a event that will be called at any time.

        modified on Tuesday, November 24, 2009 12:14 AM

        M 1 Reply Last reply
        0
        • A akira32

          FPS is frame per second. Sorry! m_FPS is customized strcut as below: ref struct sFPS { sFPS() { Init(); } void Init() { FrameCnt=0; TimeElapsed=0; dFPS=0; } void CalculateFPS() { dFPS = (Double)FrameCnt / (TimeElapsed/1000.0f); } DWORD FrameCnt; DWORD TimeElapsed; Double dFPS; }; In MFC project, I can use the CWinApp::Idle to count the frame number for FPS. But in CLR project. Application::Idle is not always called(must have some windows messages be triggerred), so I cannot use it to calculate FPS if the mouse does not focus on the winform. I want to find a event that will be called at any time.

          modified on Tuesday, November 24, 2009 12:14 AM

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          akira32 wrote:

          FPS is frame per second.

          Right. But I asked "FPS of what? What frames?" Video?

          akira32 wrote:

          I want to find a event that will be called at any time

          A Timer[^] maybe?

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          A 1 Reply Last reply
          0
          • M Mark Salsbery

            akira32 wrote:

            FPS is frame per second.

            Right. But I asked "FPS of what? What frames?" Video?

            akira32 wrote:

            I want to find a event that will be called at any time

            A Timer[^] maybe?

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            A Offline
            A Offline
            akira32
            wrote on last edited by
            #5

            Not for video. I use for DirectX.

            M 1 Reply Last reply
            0
            • A akira32

              Not for video. I use for DirectX.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              I guess I'm missing what you're trying to do. It seems to me a FPS calculation should be done when each frame (or multiple of frames) is rendered, not during an idle event, unless the idle event is the only time a new frame is rendered.

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups