I want my OpenGL updates to happen regularly. Using the JUCE Timer does not work, because as soon as there’s some work going on in the main thread, the animation is not regular anymore.
So what I did is to make my OpenGLComponent inherit from Thread too, so run() takes over the timing and the Thread runs at rather high priority 7:
void MyOpenGLComponent::run()
{
while (!threadShouldExit())
{
Thread::sleep(20); // sleep 20 milliseconds
if (contextWasCreated) // set to true at the very end newOpenGLContextCreated()
renderAndSwapBuffers(); // render!
}
}
In my first (huge) application, this works perfectly.
In my second (simpler) application, it does not work.
Is it even ok to do the animation timing like that or is it just “luck” that it worked in the first application and not the second application?
Any help appreciated! Thanks!