# Bug: When attaching an OpenGLContext to plugin, the whole UI is scaled wrong in VST2/VST3

**URL:** <https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118>\
**Category:** General JUCE discussion\
**Created:** [September 6, 2019, 5:24pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118 "2019-09-06T17:24:59Z")\
**Posts on this page:** 18\
**Page:** 1

<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:** [September 6, 2019, 5:24pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/1 "2019-09-06T17:24:59Z")

</div>

To improve rendering performance, we attach an OpenGLContext like this:

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

```

within our constructor for the PluginAudioEditor.

If we do that, our plugin is displayed incorrectly, with the graphics scaled up (probably by my monitor scale-factor of 150%) from the bottom-left corner upwards. Mouse interaction is visibly offset by a large amount.

If we don’t attach the OpenGLContext, everything renders correctly.

This does NOT happen in stand-alone mode, only when loaded as a VST2 or VST3 in Cubase 10 (Windows 64-bit). Haven’t tested other plugin formats.

When changing my desktop scale to 100%, everything works correctly.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [September 6, 2019, 6:33pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/2 "2019-09-06T18:33:10Z")

</div>

Can confirm this happens, also in FL Studio 20.5.1.

With some quick debugging, as fast as I could before deadlocking my entire system with GL + FL + my plugin in a bridged mode, `getWindowScaleFactor` reports the wrong scale in `updateViewportSize`.

---

<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:** [September 9, 2019, 4:09pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/3 "2019-09-09T16:09:35Z")

</div>

Has this begun recently? I pushed a commit setting the DPI-awareness of the OpenGL worker threads a few days ago [here](https://github.com/WeAreROLI/JUCE/commit/a37b918082b1a18d5ebbcf510bf4eba57393d6c0) which might be the culprit. Are you able to test before and after this commit to see if it’s causing the problem?

---

<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:** [September 9, 2019, 5:12pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/4 "2019-09-09T17:12:22Z")

</div>

I’ve switched to a revision from a week ago (right before you made that change) and first I was disappointed, because it looked identical, but then, after around 1-2 seconds later it redrew itself at the correct scale.

So without that fix from a week ago, it’s first scaled wrong, but after around a second or two, it refreshed (could have something to do with a “repaint” that I call once another background task completes).

I remember that before this, the scale was also always wrong, until I moved the window with the mouse and thus forced a repaint.

---

<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:** [September 10, 2019, 8:52am UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/5 "2019-09-10T08:52:33Z")

</div>

Hmm, I can’t reproduce this in Cubase 10 or FL Studio 20. My desktop scale factor is set to 175% and I’ve tried running Cubase with hiDPI enabled and disabled, and FL Studio with global scale set to “system” and other values… It could be a graphics card specific issue which will be hard to track down, but could you also try with the following modifications to the `setThreadDPIAwareness()` method in `juce_gui_basics/native/juce_win32_Windowing.cpp` at line 4098 -

```auto
JUCE_API void setThreadDPIAwareness (void* hwnd)
{
    if (setThreadDPIAwarenessContext != nullptr)
    {
        if (! JUCEApplicationBase::isStandaloneApp())
        {
            if (hwnd != nullptr && getWindowDPIAwarenessContext != nullptr)
                setThreadDPIAwarenessContext (getWindowDPIAwarenessContext ((HWND) hwnd));
        }
        else
        {
           #if JUCE_WIN_PER_MONITOR_DPI_AWARE
            setThreadDPIAwarenessContext (DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE);
           #endif
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [September 10, 2019, 12:55pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/6 "2019-09-10T12:55:10Z")

</div>

> [@](#):
>
> It could be a graphics card specific issue which will be hard to track down

I can try on my Intel GPU on my laptop at some point today and get back to you.

My test from my previous post was done on the latest NVIDIA GeForce driver at the time (436.30), using my GTX1080.

---

<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:** [September 10, 2019, 2:45pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/7 "2019-09-10T14:45:03Z")

</div>

> [@ed95](#):
>
> Hmm, I can’t reproduce this in Cubase 10 or FL Studio 20. My desktop scale factor is set to 175% and I’ve tried running Cubase with hiDPI enabled and disabled, and FL Studio with global scale set to “system” and other values…

Could you be more specific what you mean? Can’t reproduce the wrong scale being used or the first paint is wrong, then it corrects itself?

Using Nvidia 1060 and zero problems with any other apps.

---

<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:** [September 10, 2019, 2:50pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/8 "2019-09-10T14:50:47Z")

</div>

Both, I’ve built the `AudioPluginDemo` as both VST2 and VST3 and it’s rendering as expected in Cubase and FL Studio.

---

<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:** [September 10, 2019, 3:06pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/9 "2019-09-10T15:06:05Z")

</div>

With an openglcontext attached?

---

<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:** [September 10, 2019, 3:08pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/10 "2019-09-10T15:08:57Z")

</div>

Yes, it renders correctly both with and without an `OpenGLContext` attached. Are you able to reproduce the issue by just adding an `OpenGLContext` to the vanilla JUCE `AudioPluginDemo` and calling `attachTo()`?

---

<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:** [September 10, 2019, 4:33pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/11 "2019-09-10T16:33:20Z")

</div>

The demo plugin with an OpenGLContext attached renders correctly, but strangely NOT when opened for the first time.

So you start Cubase 10, load the AudioPluginDemo as a VST3 instrument, and when opening the GUI it looks like this:

![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/f/f7a4f1b3aa02dd219ba04789ff4225e3315c803f.png)

Then, when only changing the height of the window, it looks like this:

![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/7/743ab3af7c87e7401d2417a24fd3d4be3488f626.png)

You can clearly see the cropping and how badly upscaled everything looks (pixels are scaled by 150% without even linear interpolation)

After increasing the height (or width) further, suddenly the whole GUI corrects itself and renders correctly:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/3/3d2f06fc69759625aa435e7c3b1c82d0e301e9da.png)

Before the “fix” a week ago, and with our plugin, it worked just way better.

---

<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:** [September 10, 2019, 4:51pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/12 "2019-09-10T16:51:06Z")

</div>

Did you try with the change I posted above?

---

<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:** [September 10, 2019, 5:11pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/13 "2019-09-10T17:11:07Z")

</div>

I’ve just made the change you described above (copy’n’pasted the entire block) and it makes no difference for our plugin in Cubase 10 (didn’t test with the AudioPluginDemo).

It worked really better before you made the change a week ago for “Cantabile”, a host nobody ever heard of and not used by a single customer of ours we are aware of, while it broke compatibility with Cubase, a major host on the market.

I highly doubt it’s a graphics-card specific issue. The Nvidia cards we use are extremely popular and we have exactly zero graphical issues otherwise.

Again: it worked fine a week ago. It broke with the commit that fixed the issue in “Cantabile”.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [September 10, 2019, 5:22pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/14 "2019-09-10T17:22:47Z")

</div>

> [@Toddler-Boy](#):
>
> Before the “fix” a week ago, and with our plugin, it worked just way better.

What does this even mean? It’s either it works as expected or it doesn’t.

---

<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:** [September 10, 2019, 5:37pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/15 "2019-09-10T17:37:07Z")

</div>

It’s not always so cut and dry. It worked better, as in it displayed with the wrong scale for about a second and then redrew itself correctly right after.

---

<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:** [September 11, 2019, 3:39pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/16 "2019-09-11T15:39:15Z")

</div>

> <https://github.com/WeAreROLI/JUCE/commit/6f4d212ca6964b6dd6e83e4f19be35ec1cbda2ba>

---

<div class="post-metadata">

**Author:** ![jcomusic](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jcomusic/32/2014_2.png) [@jcomusic](https://forum.juce.com/u/jcomusic)\
**Post date:** [March 4, 2021, 11:44am UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/17 "2021-03-04T11:44:52Z")

</div>

I’m having this exact issue with JUCE 6.0.5 now.

---

<div class="post-metadata">

**Author:** ![jcomusic](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jcomusic/32/2014_2.png) [@jcomusic](https://forum.juce.com/u/jcomusic)\
**Post date:** [March 4, 2021, 12:08pm UTC](https://forum.juce.com/t/bug-when-attaching-an-openglcontext-to-plugin-the-whole-ui-is-scaled-wrong-in-vst2-vst3/35118/18 "2021-03-04T12:08:22Z")

</div>

In rare cases moving the windows, opening the start menu or alt-tabbing “magically” fixes the rendering. This is very random though. I get a strong feeling that this might even be a windows or a gpu driver issue… regardless of that, I urgently need some sort of work around. Experimenting with window creation and dpi awareness setters now 😕
