Can I have more than one OpenGLAppComponent?


Hi, I’ve just successfully rendered an OpenGL thing in a component window by inheriting an OpenGLAppComponent, I’m letting it render itself just like in the OpenGLAPPDemo - very cool.

I’d like to know if I can create another window in the same plug-in context? Or can there be only one of them due to the nature of OpenGL and its single thread calling?


You can have a second window, it will just have a second juce::OpenGLContext associated with it (and each context will spawn its own thread to use).

If you’re on Linux, be sure your copy of JUCE includes this commit when using multiple instances of juce::OpenGLContext:


Brilliant, thanks man! I have found a slight problem associated with a scaling of 1.5 which is what I use as a Windows 10 default setting.

In your GL demo app it sets a viewport in Render() with a variable ‘scale’ that’s set to 1.5, but I only get a scale of 1.0 in my plug which makes the GL window (the teapot) shift to the bottom left. This is using the exact same code as the demo.

I think it’s because the context’s referenced peer() is my plug-in’s context rather than the main window? I’ll have to edit or copy the Juce code to fix it if it’s true. Is that the cause?

I can do without the viewport call, which will make it work as normal, but it would be nice to make it the correct area.
Thanks again.


It sounds like you might be running into:

In our plugins we use a similar approach to what trickyflemming suggests: we have a container that handles resizing our view through an AffineTransform. We have OpenGL components as well in our plugs and I haven’t run into any scaling issues yet with this!


Interesting, thanks, and worrying. Yeah I have a 4K and I’ve used OpenGL for years (outside Juce) in plugins, and I’ve never had a problem with full plugin window Gl contexts. I just let Windows deal with the scaling automatically. It might be doing odd pixelations but I haven’t noticed myself. Like I said - so far it seems OK if I don’t set a viewport in the Render() function - but that needs more tests. Fl studio has it’s own scaling gui settings now which is another factor to look at. Hmm it’s late, so l’ll start again tomorrrow…