GL backing scale problem on Retina


#1

 

 

I noticed a small problem with the code that gets the GL context scale in the GL demo. 

In OpenGLDemo.cpp, where you have:

double getScale() const 
{ 
  return Desktop::getInstance().getDisplays().getDisplayContaining (getScreenBounds().getCentre()).scale; 
}

I think you want something like:


double getScale() const 
{ 
  ComponentPeer* peer = getPeer(); 
  if(peer) 
  { 
    Rectangle<int> peerBounds = peer->getBounds(); 
    return Desktop::getInstance().getDisplays().getDisplayContaining(peerBounds.getCentre()).scale; 
  } 
  else 
  { 
    return Desktop::getInstance().getDisplays().getDisplayContaining(getScreenBounds().getCentre()).scale; 
  } 
}

This is because the NSWindow will scale the backing GL context according to its center, not the Component’s center. When the GL view center happens to be centered on the Window as in the demo, one won’t notice the problem. 

I don’t know exactly why getPeer() would return null, so maybe there’s a better fallback in that case. 

Since this is potentially needed for lots of GL drawing, I would advocate for adding it to OpenGLRenderer as getBackingLayerScale() or similar.




#2

Thanks, yes - I've been doing a lot of work on the display scale stuff lately, and some of the demo code needs updating - I'll sort that out!