I have been using openGL for component 2D rendering since it showed up in Juce, and it’s always been amazing of course.
Recently, I notice that if I resize my top level component, I get flickers of red as the openGL canvas (presumably) resizes / swaps / clears / redraws. This shows up as bars on the right and lower sides of the component of course.
I suspect this may have always been happening but previously it wasn’t bright RED.
Is it possible that either the openGL clear color, or some other color, has recently changed?
Is there a way I can set it manually? I don’t see that anywhere at a quick glance.
The “stuttering” can be seen in this topic, when you resize the component:
I assume that is somewhat inevitable, since openGL is on a different thread, but it’s not really a problem as long as the extra area is white.
Aha! Looks like I can clear manually in resize() using a helper.
Still seems like it might be better to default clear GLContexts to white, but for anyone else getting this issue, adding this sort of thing to the resize seems to do the trick.
if (OpenGLHelpers::isContextActive())
{
OpenGLHelpers::clear(Colours::blue);
}
This has always driven me crazy as well. It’s confusing how the frame can change sizes faster / slower than the internal window it contains, but the red background it displays is the worst of it. Thanks for the tip! Gonna give it a shot as well
I got the same problem as jakemumu.
Even though I attached my GL context using mGLContext.attachTo(*this) I get false for isContextActive in the resized function.
Here is how I could solve it instead:
I subclass juce::OpenGlRenderer. And in its renderOpenGl() function I put this:
void MyOpenGlRenderer::renderOpenGL()
{
if (OpenGLHelpers::isContextActive())
{
OpenGLHelpers::clear(Colours::blue);
}
}
Now I only have to tell my GL context, that I am using a custom renderer, by calling:
I was unaware, but openGL calls (like OpenGLHelpers::isContextActive()) are not guaranteed to be thread safe (so should only be called from paint and renderOpenGL).
So far I have no solution for this, I’m just dealing with the red.
Are you referring to Aarons solution or to my solution?
I am still using my solution (which is different from Aarons solution). And it has been fine so far. No more red flashing. And no crashes or asserts with it so far (don’t have Pro-Tools though, so cannot test there). As mentioned above, in my solution I subclass the juce::OpenGlRenderer.
That way I am only calling OpenGLHelpers::isContextActive() from within OpenGlRenderer::renderOpenGL(). Which should be OK, if I understand Aaaron and Reuk
correctly.