elmindreda/glfw — pull request #36 by eropple (2013-02-16 04:04:05+00:00)
Title: HiDPI/Retina support for OS X

This commit (squashed from eropple/glfw:hidpi-support) provides support
for HiDPI mode on Retina MacBooks running OS X. It includes the
following changes:

- Defines GLFW_HIDPI_IF_AVAILABLE as a flag for glfwWindowHint.

- Adds 'wantsHiDpi' (GLboolean) to _GLFWhints and _GLFWwndconfig.
- Adds 'scale' (float) to _GLFWwindow.
- Adds glfwGetWindowScale, which returns _GLFWwindow.scale.

- Wires up GLFW_HIDPI_IF_AVAILABLE to set _GLFWhints.wantsHiDpi, which
is then stored in _GLFWwndconfig.
- If _GLFWwndconfig.wantsHiDpi is set, requests a Retina-capable OpenGL
surface for GLFW and requests the backing scale factor from Cocoa
(2.0 for Retina, 1.0 otherwise).

- Modifies the 'wave' demo set GLFW_HIDPI_IF_AVAILABLE (and it looks
great!)

While in the OS X documentation it makes note of the need to adjust
between screen coordinates (in Cocoa 'points') and view coordinates (in
pixels), I have not written a function to do so because I wasn't sure of
the most idiomatic way to do it for GLFW. I feel like this is probably a
good idea because of the slightly janky code that you can see in the
wave example; I pull the scale factor and multiply the width and height
in the glViewport call by that value. That seems like something that
might be better handled by the library in some way. It is, however, a
pretty minor thing.

This code has been tested to work successfully (via the modified
wave example) on OS X and Windows. It has not been tested on X11, but
nothing should have changed in any of its code paths to cause a problem.

API-compatible with all previous GLFW3 code. Not ABI-compatible.

Credit is due to @filipwanstrom for his original work adding Retina
support to GLFW 2.7; I used it as a guide in my implementation.