I’ve got some animations running in an OpenGL context window, so I need to constantly redraw it. So I came up with the following code:
private void InitializeRedrawTimer()
{
var timer = new Timer();
timer.Interval = 1000 / 60;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
private void timer_Tick(object sender, EventArgs e)
{
glWin.Draw();
}
That only gives me 40 FPS though. If I set the interval to 1 ms however, I can achieve 60. So where did the other 20 ms go? Is that just due to poor accuracy of the timer or what? What if I wanted to let my program run as fast as possible, is there a way to continuously call the draw func?
You could try implementing a game loop.
https://learn.microsoft.com/archive/blogs/tmiller/my-last-post-on-render-loops-hopefully
This link describes one that uses the application’s Idle event. It may be of use. You can simply perform a little time test or sleep to slow it down to your required fps. Try using the System.Diagnostics.StopWatch class for the most accurate timer.
I hope this helps a little.