# Calculate frame rate Direct3D C#

This topic is 4775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, How can I calculate on my own how many frames there are at one second. (Not using the SDK user interface) and besides that give a limit to it (for use with audio video playback) Greetz, Johan Reitsma

##### Share on other sites
Quote:
 Original post by jcr83Hi,How can I calculate on my own how many frames there are at one second.(Not using the SDK user interface)Greetz,Johan Reitsma

You need only two pieces of information for this:

1. Some counter of how many times you've rendered (often how many Present() calls have been made).

2. A timer to indicate how much time has elapsed since you last checked.

The first one is pretty simple, but the second one you might have to look up some of the basic timing functions in the .Net API.

A trivial implementation, in pseudo code, would be:

//Place this right after a scene has been renderedif( (current_time - last_checked_time) >= 1000ms ) then   current_frame_rate = frames_rendered    //copy this for use later in text output   frames_rendered = 0  //reset the counter for the next 1-second interval   last_checked_time = current_time //reset the timer to start counting againelse   frames_rendered = frames_rendered + 1end if

hth
Jack

##### Share on other sites
There are also an insane INSANE amount of wars right now on the proper
"main loop" structure within a Managed C# game. This could also directly

Google for Tom Miller's blog and he mentions a link on the current "best practice"
for the main loop.

##### Share on other sites
Ugh, timing in C#.. last time i checked the best way was to somehow attach the win32 dll to get the QueryPerformanceCounter functions :S

That's pretty much when i descided to stop looking into c# mdx.. that and the fact that templates doesn't exist, yet.

Oh hell, the main loop thing. That was the first question i was asking myself - "pumping paint messages, that can't be the way to do it"... then we have the Render(); App.DoEvents(); design which makes alot more sense but still.

When it comes to mdx c#, what they're lacking is the thing they're saying they have, standards.

• 23
• 10
• 19
• 15
• 14