retro_alt's picture

Proper Way To Limit Framerate On A GLControl?

Hi-

I have the GLControls working perfectly using the Application.Idle event to .Invalidate() the control and trigger a paint event as explained in the tutorial. The problem is that it is smoking my CPU, rendering thousands of frames per second, even with VSync enabled. If I use System.Threading.Thread.Sleep(10), it sleeps the main form as well.

What is the proper way to limit the framerate on a GLControl? Another thread dispatching the .Invalidate() calls maybe?

Thanks!
Greg


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Kubajzz's picture

I would suggest using a Timer and call the Invalidate() function from there.

See System.Windows.Forms.Timer or System.Threading.Timer (I don't really know what's the difference between the two... You choose which one suits your needs)

zahirtezcan's picture

Threading.Timer is using a seperate thread and triggered between sleeps imho. Windows.Forms.Times is triggered via application message loop (it is on the same thread in which controls are created, key/mouse events are fired), so it is the best way to limit refresh rate to screen refresh rate. (It is fixed to 60Hz on my lcd even if i set the interval to 1ms)

retro_alt's picture

Thank you,
Thank you,
Thank you!

I've been trying to figure this out for like a week!

Greg