# Autoscaling OpenGL Component bug. Windows only

**URL:** <https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578>\
**Category:** General JUCE discussion\
**Created:** [October 6, 2019, 6:16pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578 "2019-10-06T18:16:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 6, 2019, 6:16pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/1 "2019-10-06T18:16:59Z")

</div>

Hi, I’ve been using the auto scaling feature in Juce, where any sub component is scaled for you. It’s a fantastic feature if you’re using resizing.  
BUT it doesn’t work with a component with a ‘OpenGLRenderer’ added to it.  
This is on ‘develop’ & ‘master.’

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 7, 2019, 2:30pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/2 "2019-10-07T14:30:16Z")

</div>

So to summarise.  
I use:

```auto
class MainPanel : public Component,
                    public OpenGLRenderer
{
}

```

& Do…

```auto
openGLContext.attachTo(*this);

```

…In the constructor.

The above attachment destroys any internal scaling it should have got from its parent. But still scales it’s own child Components, which means the whole thing becomes a mess, as the child components outscale it when enlarged.  
Removing the ‘attachTo’ makes it scale work OK again - except of course I have no OpenGL rendering.  
This is only Windows, BTW. MacOSX appear to scale fine, on both VST & AU.  
Can anybody help please?  
Thanks.  
Dave H.

BTW. I’m using setTransform only on the very top Window Component, and all my other sliders, text objects etc scale properly.

---

<div class="post-metadata">

**Author:** ![stenzel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stenzel/32/11737_2.png) [@stenzel](https://forum.juce.com/u/stenzel)\
**Post date:** [October 8, 2019, 2:11pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/3 "2019-10-08T14:11:46Z")

</div>

Can confirm I have exactly the same problem, would love to see this fixed soon.

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [October 8, 2019, 4:30pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/4 "2019-10-08T16:30:36Z")

</div>

If all you’re trying to achieve is making Juce use the OpenGL context for its own drawing functions, you don’t need to inherit from OpenGLRenderer. Simply attach the context and you’re good to go. Works fine here.

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 8, 2019, 4:35pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/5 "2019-10-08T16:35:00Z")

</div>

But that’s what I wanted to do. You also inherit some functions.  
The point is that it SHOULD work like it does on Mac.

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [October 8, 2019, 5:35pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/6 "2019-10-08T17:35:18Z")

</div>

> [@DaveH](#):
>
> The point is that it SHOULD work like it does on Mac.

How do you know that it working on Mac isn’t sheer luck / coincidence and what you’re trying to do here is even supported?

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 8, 2019, 5:39pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/7 "2019-10-08T17:39:44Z")

</div>

It is supported. People have been using it. It was recommended on this forum to do that so all the child components get scaled with the parent.  
It saves doing all the manual bounds setting in resized().

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [October 8, 2019, 5:49pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/8 "2019-10-08T17:49:04Z")

</div>

Again: we are also using an OpenGLContext to speed up our rendering AND we scale our entire UI by using transforms.

You do **NOT** need to inherit from the OpenGLRenderer class to do that. The OpenGLRenderer class is designed to let you render OpenGL stuff from a background thread.

It all works fine on Windows (our primary development platform). All you need to do is add a member variable of the type “OpenGLContext” and then attach it

In your plugin-editor class definition somewhere:

```auto
		OpenGLContext openGLContext;

```

Somewhere in your constructor of your plugin-editor:

```auto
		openGLContext.attachTo ( *getTopLevelComponent () );

```

That’s literally all that is required. No need to inherit from OpenGLRenderer and confuse/break the rendering.

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 8, 2019, 5:56pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/9 "2019-10-08T17:56:01Z")

</div>

When does it render your OpenGL if renderOpenGL() isn’t called?  
What about setContinuousRepainting(true) ?  
When do you create your shaders if newOpenGLContextCreated() isn’t there?  
How do you get rid of your resources if openGLContextClosing() isn’t called.

Surely inheritance is the best way to use it?  
Anyway, you’re obfuscating the bug.

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [October 8, 2019, 6:14pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/10 "2019-10-08T18:14:31Z")

</div>

Simple misunderstanding. I thought you wanted to simply accelerate the standard Juce UI drawing and scale it. There really is no need to be so hostile.

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 8, 2019, 6:24pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/11 "2019-10-08T18:24:47Z")

</div>

I didn’t even know standard Juce UI stuff could be sped up like that! LOL.

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 10, 2019, 2:43pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/12 "2019-10-10T14:43:32Z")

</div>

Is there any chance someone from Juce can look into this, please? It’s breaking my whole rendering chain, because I added the OGL panel late in development, and I’ll have to go back to manually scaling everything again, which would be a shame is it may be a simple thing to fix?  
Thanks.

_edit_ this is also nothing to do the Windows scaling. As it goes wrong irrespective of any Layout Scale.

Dave H.

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 10, 2019, 5:12pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/13 "2019-10-10T17:12:50Z")

</div>

@ [Stenzel](https://forum.juce.com/u/Stenzel)  
OK I just managed to use a **hack** for this to work!! It is dodgy though, but you don’t have to alter any Juce code to ‘fix’ the problem.

You have to make the OpenGL component think it has been resized.  
By:

```auto
viod MyEditor::resized()
{
.
.
 	editorBase->panel->setBounds(24, 24, 976, 400); // *NB. Last parameter changed!
	editorBase->panel->setBounds(24, 24, 976, 402);
}

```

The second one being the bounds I actually want.  
So I’m guessing there’s an ‘if’ somewhere that doesn’t check the parent transform changing on Windows. I don’t know for sure, it just looks like that, 😃

---

<div class="post-metadata">

**Author:** ![stenzel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stenzel/32/11737_2.png) [@stenzel](https://forum.juce.com/u/stenzel)\
**Post date:** [October 11, 2019, 2:07pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/14 "2019-10-11T14:07:00Z")

</div>

Thank you Dave!

I already have the same workaround hack in my code because Juce cannot handle changes to the component hierarchy during runtime.

It would be nice to get an official statement from Juce maintainers regarding this bug.

Stefan

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 11, 2019, 2:41pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/15 "2019-10-11T14:41:09Z")

</div>

@Stenzel  
Why didn’t you let me know about your ‘fix’? It would have saved me a week of heartache and worry! 😁  
Juce transform hierarchy does work outside OpenGL components though. Also this is a Windows only bug.  
Yeah, this forum can make us feel left alone sometimes.  
Laters,  
Dave.

---

<div class="post-metadata">

**Author:** ![stenzel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stenzel/32/11737_2.png) [@stenzel](https://forum.juce.com/u/stenzel)\
**Post date:** [October 11, 2019, 3:20pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/16 "2019-10-11T15:20:18Z")

</div>

Dave,

That hack fixes a completely unrelated Juce problem that also occurs on macOs.

In my case this helped:

```
setBounds(1,0,w,h);
setBounds(0,0,w,h);

```

And yes, it also took me several attempts to solve it in a clean way until I gave up.

Stefan

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 11, 2019, 3:26pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/17 "2019-10-11T15:26:08Z")

</div>

Can you say what the unrelated problem is, and did you report it to the github issues list?

---

<div class="post-metadata">

**Author:** ![stenzel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stenzel/32/11737_2.png) [@stenzel](https://forum.juce.com/u/stenzel)\
**Post date:** [October 11, 2019, 4:09pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/18 "2019-10-11T16:09:31Z")

</div>

@DaveH  
Dave,

I have a base component that is usually parent of all other UI components, including one with an OpenGLContext attached. During runtime, the OpenGL component can be switched to occupy the whole window, in this case the relation of both components is reversed, meaning the former parent becomes the child and vice versa. All child components remain children of the former base component, except the former OpenGL component.  
Juce cannot handle this properly, but with the above mentioned hack it works.  
(And no, the component hierarchy is not cyclic at any point.)

Can you point me to the github issues list? Didn’t know about these.

Stefan

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 11, 2019, 5:58pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/19 "2019-10-11T17:58:54Z")

</div>

> [@Stenzel](#):
>
> Can you point me to the github issues list? Didn’t know about these.

The usual place you get the code… second tab from top left.

> **[GitHub - juce-framework/JUCE: JUCE is an open-source cross-platform C++...](https://github.com/juce-framework/JUCE)**
>
> JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, LV2 and AAX audio plug-ins. - GitHub - juce-framework/JUCE: JUCE ...

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [October 15, 2019, 1:34pm UTC](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578/20 "2019-10-15T13:34:40Z")

</div>

> [@DaveH](#):
>
> Yeah, this forum can make us feel left alone sometimes.

Rest assured that we do read every post and we’ll investigate and respond to posts that require our attention. With ADC coming up next month things are rather busy so unfortunately our response times might be slightly longer than usual.

Can you see if the following commit fixes the issue for you?

> <https://github.com/juce-framework/JUCE/commit/558ca3e5e6a731513de56c0cf3ad9120db70b449>

[Next page](https://forum.juce.com/t/autoscaling-opengl-component-bug-windows-only/35578.md?page=2)
