locked
How do I display Frames Per Second?

    Question

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

Answers

  •  

    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:27 AM

All replies

  • 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 1:47 AM
  •  

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