Should I use Thread or Timer for animation fps counting?

I’m working on an OpenGL video game animation project.

I did some research into Timer’s, and it appears there is a limitation of 15ms on the timers for windows. I’m also not entirely sure if Timer’s is even the correct way to go as I want to program a way to figure out what the FrameRate is.

I’m thinking of using a Thread and putting a while loop in it and using Microseconds. I can compare the different times it took to render the frame and come to conclusions this way but I’m not sure if this is the best way to do this?

Any thoughts? Can someone show me the code they use to calculate frame rates?

I would definitely use a Timer. Thread is designed to solve a different problem, and using it for what you describe is definitely not it.

Well from what I read, you are not supposed to update the interface via a thread, so in that regard I should never run the openGLSurface render command from the thread it would seem. If I use a timer however, I am limited to 15ms on Windows (from what the documentation says). I’m not sure what to do.

Maybe I am just limited to 15ms (or roughly 60~ FPS readings)?

Here is the code for a function I came up with, best frame rates I can read are 60 FPS, but it’s likely it’s going faster.

[code]GameOpenGLSurface.Render() //attempts to render the scene every 15ms

deltaTicks = Ticks - previousTicks //The difference between these ticks is the ‘true’ time for this frame.

previousTicks = Ticks //set the previousTicks for the next frame check.

timeSum = timeSum - timeList(timeIndex) //subtract the falling off value.
timeSum = timeSum + (deltaTicks/60) //add the the current seconds
timeList(timeIndex) = (deltaTicks/60) //save the current timeList index so it can be subtracted later

timeIndex = timeIndex+1//increment the timeIndex.

if(timeIndex=100) then //set array index back to 0 to reset.
timeIndex = 0
end if

FPS = timeSum/100 //divide the sum of the times by 100 to get the FPS.

FPS = 1/FPS //the answer will be in seconds per frame, therefor, take 1 second divided by the time it took and that is the FPS.

mainWindow.Title = “FPS: “+str(FPS,”#.000”)+" / second"[/code]

I created 5 properties in the mainWindow for this:

previousTicks as double
timeIndex as integer
timeList(100) as double = 0
timeSum as double = 0
FPS as double = 0

I am still not sure if a Timer is the best place for this since the best reading I can possibly get is 60 FPS due to the restrictions of the timer it’s self.

Why not just measure the time it takes to run a paint event and use that?

Dim Start As Double = Microseconds
// Paint
Dim Elapsed As Double = Microseconds - Start

Now you know how long the paint took. You can even keep an average.

A thread would have a similar periodic iterruption. A timer can fire down to about 1 ms, but there’s a periodic gap of about 15ms from something that occasionally happens in the event loop.

Do you have any suggestions for seeing a frame/rate above 60fps? Or is that the best Xojo can do? (Which is fine), but I just want to know my options so I’m doing the right thing.

I suggest using a timer, it seems to be accurate. After intentionally overloading the video with information, or increasing the size of the screen with rapid updates, the fps are pretty accurate.

Here is the link to a free download of OpenGl programs and a book on Xojo with Windows . The download is at the bottom of the web page. Its not complete, and there are some programs which you can examine that are explained in the book.