Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Locked How do I display Frames Per Second?

  • Tuesday, April 04, 2006 1:41 AM
     
     
    The subject says it all; how do I see what FPS my app is getting? DirectX must be stashing that info somewhere!

All Replies

  • Tuesday, April 04, 2006 1:47 AM
     
     

    Every example I've seen requires working it out by using a timer and counting how many times a second the screen gets refreshed. 

    But it's possible that it's sitting in there also, it's been a while since I did DX.

     

  • Tuesday, April 04, 2006 3:27 AM
     
     Answered

     

    Have a look at the following sample... Call the CalculateFrameRate each time you render to the device, and either display it to the device in code or change you forms title text to display it ie. thisform1.title.txt = CalculateFrameRate().ToString();

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace VirtualRealm.Mdx.Common
    {
        public class Utility
        {
            #region Basic Frame Counter

            private static int lastTick;
            private static int lastFrameRate;
            private static int frameRate;

            public static int CalculateFrameRate()
            {
                if (System.Environment.TickCount - lastTick >= 1000)
                {
                    lastFrameRate = frameRate;
                    frameRate = 0;
                    lastTick = System.Environment.TickCount;
                }
                frameRate++;
                return lastFrameRate;
            }
            #endregion

        }
    }

  • Tuesday, April 04, 2006 3:57 AM
     
     
    Does C# have an equivalent method to System.getNanoTime() in Java? That would make life alot easier...
  • Tuesday, April 04, 2006 4:40 AM
     
     
    Environment.TickCount is probably what you are looking for.
  • Tuesday, April 04, 2006 11:22 AM
     
     
    Cool! Thanks for the code.