title: HiDPI / backingScaleFactor on MacOS, how to get actual value?
body: <p>I'm trying to get the display scaling setting for the current screen so that I can correctly scale inside my OpenGL and/or Vulkan window to match the setting that the OS has. The documentation says to use</p>
  
  <pre><code>float dpi = [window backingScaleFactor];
  </code></pre>
  
  <p>However this will return 1.0f for no scaling at all, and 2.0f for some scaling.</p>
  
  <pre><code>float dpi = [[window screen] backingScaleFactor];
  </code></pre>
  
  <p>does the same.</p>
  
  <pre><code>NSRect resolution = [[window screen] frame];
  </code></pre>
  
  <p>will give you the virtual resolution of the current screen. In System Preferences -> Display -> Scaled, this is the "Looks like" value. For a 3840x2160 screen I have, the possible values are 1920x1080, 2560x1440, 3008x1692, 3360x1890, 3830x2160, depending on the Scaled setting you have chosen. On my MBP's built in screen, which has a native resolution of 2880x1440, the "Looks Like" values can be 1024x640, 1280x800, 1440x900, 1680x1050, 1920x1200. <a href="https://developer.apple.com/documentation/appkit/nsscreen/1388385-backingscalefactor?language=objc" rel="nofollow noreferrer">the docs</a> say to use</p>
  
  <pre><code>NSRect test = {0, 0, 1000, 1000};
  NSRect dpi = [NSView convertRectToBacking:test];
  </code></pre>
  
  <p>However this just multiplies the supplied <code>NSRect</code> by the <code>backingScaleFactor</code>.</p>
  
  <p><a href="https://stackoverflow.com/questions/13859109/how-to-programmatically-determine-native-pixel-resolution-of-retina-macbook-pro">This</a> is someone trying to get the real resolution of the screen.</p>
  
  <p>So, I want either the real <code>backingScaleFactor</code>, or the native screen resolution for a given <code>NSScreen</code>. Any ideas?</p>