OpenGL 2D rendering RED on resize

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.

This is on mac OS11 by the way.

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);
}
1 Like

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

This just confused me… I get false back for isContextActive() when I initialize the render on the top level component like:

mGLContext.attachTo(*this);

Is this different than how you’re rendering via OpenGL?

Well, it doesn’t attach immediately.

I use that clear call in the resized() method.

hmm yeah in my resize it was false on return

I’m seeing the same issue as well.
The correct clear should probably done in Juce itself rather than in user code no ?

1 Like

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:

mGLContext.setRenderer(&mMyOpenGlRenderer);

Seems to work fine so far (fingers crossed)!

1 Like