tags:

views:

28

answers:

1

Hey guys, and thanks for looking. I have built the simple D2D app from MSDN, available here. Now, I want to draw some primitives and add an fps counter.

I have an OnRender() event, where I draw the rectangles and so on. I also have a call to RenderTextInfo() where I call RenderTarget->DrawText. Where do I add the logic for counting the number of frames per second?

Thanks much.

+1  A: 

I don't know the exact Direct2D stuff, but this might help.

Basically, you have two choices. Either you update the framerate when you draw a frame, or each second (or any other time interval).

If you count it when you draw a frame, you can simply get the current time when you draw a frame, and subtract from it the time you drew the last frame. That gets you the time spent drawing this frame. The reciprocal of that (i.e. 1/x) is the framerate.

If you count it at a regular time interval, you need to have some event firing at every interval that checks how many frames were drawn since the last time that event fired. Divide that by your interval (if it's one second, you don't need to divide, of course) and that's your fps count. Don't forget to increment some counter every time you draw a frame.

Martinho Fernandes
Thanks Martinho, this helps a lot. I'm looking at the functions in time.h to get what I want. Unfortunately, I've discovered another problem--the screen doesn't redraw anything once the original primitives are drawn. I'll post another question on this.
Freakishly
Okay, I used the 1/x logic to calculate the framerate and it worked. Thanks, Martinho :D
Freakishly