OpenGL: Problems with scaling in high dpi displays

In our application we found problems with OpenGL in high DPI and Retina displaysThe scaling doesn’t works, it should be a Juce bug, because the code is working well until HD Displays (max. 1920 x 1080). Furthermore (f.e. we tested it on a display 4096 × 2304) the elements drawn with OpenGL are not placed at the right position, they are not right scaled. The same problem appears in OSX, Windows and Linux. I found some posts about patches in the developer branch, I don’t know exactly if there is a solution for this problem now or what patch should I apply.
This is an example of this problem:

Can you reproduce this with any of the JUCE examples? I can’t see any issues with any of the OpenGL demos or the DemoRunner using the OpenGL renderer setting on a 2560x1440 display on macOS.

@ed95 Many thanks for your answer. I’ll try to do it tomorrow (Monday), I don’t have an OSX computer with retina display at home, my display have 1920x1080, here works all fine.
Before the last Juce upgrading to 5.4 we had problem with the score drawn at the background (I speak always about high DPI resolution, not about “normal” displays), the score was “stretched”, the cursor was drawn at the right position, we solved this problem with the following hack:
const float desktopScale = openGLContext.getRenderingScale(); //takes retina scaling into account
setTransform(juce::AffineTransform.scale(desktopScale, desktopScale));

The background score is drawn with Juce Graphics. after the last upgrade to 5.4 the score was not stretched anymore, but the cursor is always false.
Alternatively I can send you a link to download a demo program as a PN. I can try to make a minimal example too, but maybe this is not going to be easy.

If you can reproduce the issue with a minimal example or show that one of the JUCE demos exhibits the same behaviour then that would be useful in tracking down where the problem might be.

I don’t know if this helps, but I came across what might be the same issue last week.

I was working on an OpenGL component that needed to be “transparent”. So I save the background of the parent (which happens to just be a preloaded image) and create a texture from it to render as part of the renderOpenGL method.
I found I had to scale the background image according the current scale factor to get it to display at the correct size:

    auto scaleFactor = Desktop::getInstance().getDisplays().getMainDisplay().scale;
    myOpenGLComponent.backgroundImage =
            std::make_unique<Image> (bgImage.getClippedImage (clipBounds)
                                            .rescaled (clipBounds.getWidth()*scaleFactor, clipBounds.getHeight()*scaleFactor));

Thanks for your answer. @adamsky I implemented your proposal in the following way:
double scaleFactor; // class member
scaleFactor = juce::Desktop::getInstance().getDisplays().getMainDisplay().scale; //in class' constructor
if(scaleFactor > 1) { setTransform(juce::AffineTransform::scale(scaleFactor, scaleFactor)); } //after the Openglcontext was initialized
Now works, many thanks for your help. The code works on Linux and windows too.
@ed95 after the last update to the XCode 10.2 OpenGL still doesn’t works properly, in the above example the execution takes about 50% CPU Usage. I think it’s time to add Vulkan support on Juce …