0

So I have this nice c# application written with OpenTK (OpenGL) ... it uses a full screen GL Window and like it's supposed to, it auto runs the OnRenderFrame method whenever it can, and I get a great 60 FPS game.

BUT, now I wish to use my game within a GLControl in a Windows Form rather than a GL window. For whatever reason it runs the onrenderframe method once and that's it. I tried using Application.Idle to run it like it says in their documentation but I end up getting about 5 frames per second.

How am I supposed to make it run on a loop like the original application?

EDIT: Basically what I'm looking for is something similar to the game.Run(60) you would use to initialize an OpenGL window at 60 frames per second.

genpfault
  • 51,148
  • 11
  • 85
  • 139
stingray-11
  • 448
  • 2
  • 7
  • 25
  • Could you please provide the code for what you have already tried? – antonijn Feb 18 '13 at 20:45
  • The MainForm.Load event fires a load() method which says Application.Idle += OnRenderFrame; This gets me about 6 frames per second. – stingray-11 Feb 18 '13 at 20:47
  • WOAH! I found something very strange. Using application.idle to update the frames, if I wave my mouse side to side on the window continuously or hold down a key on the keyboard THEN it stays at a perfect 60 frames per second. Why does that happen and how can I make it always happen?? – stingray-11 Feb 18 '13 at 21:00

2 Answers2

1

GLControl is event-based, so every frame will be rendered only after manual GLControl.Invalidate() call.

Actually you don't need high fps all the time. You need only to render changes. So variable fps might be enough good for you, as it takes less system resources.

Fps value while input is active depends on input device, for example, my touchpad gets ~60 events per second, and a4tech mouse with 1000Hz sampling frequency gets ~750 fps on the same basic sample.

Anyway, if you insist on constant fps, you may call Invalidate() in a timer, as said above.

Alexey
  • 63
  • 1
  • 8
0

Make a timer that calls GLControl.Invalidate() every 1/60th of a second. Also, I do not recommend using Application.Idle to run the animation as it has unexpected behavior. Are you swapping buffers correctly?

TheBlindSpring
  • 631
  • 5
  • 22