Code examples how to setup Retina

Is there any code examples how to set up a glfw an application to work properly with a retina display?
It not very clear if GLFW_COCOA_RETINA_FRAMEBUFFER should be used, or if cursor position needs to be scaled, etc. Unfortunately I do not have a retina device to test on, that’s why example code would be helpful

I don’t have a retina device, but here’s some guidance:

GLFW_COCOA_RETINA_FRAMEBUFFER is only required if you don’t want the higher resolution framebuffer. If you have a demanding application which is bound by a performance constraint which scales with resolution this may help, but a better approach which will work across all systems would be to use something like Dynamic Resolution Rendering, the basic implementation being pretty simple to set up.

The Cursor position is measured in screen coordinates - i.e. the same ones used to create, resize and position your window. So you don’t need to

Your projection matrix can stay based on the window size in screen coordinates since it is a ratio which projects to clip-space (-1.0 to 1.0 range for each axis). If you do this then you can transform the mouse position to clip-space.

You need to use the framebuffer size for your viewport, clipping, render targets etc. You should use this in the code for every platform.

For rendering text make sure to scale the resolution of the text by the framebuffer to to window size if you keep your text to window size ratio the same.

Hope this helps.

Thanks for the answer.
Setting GLFW_COCOA_RETINA_FRAMEBUFFER to false ensures that glfwGetFramebufferSize and glfwGetWindowSize both return the same values, right?

This should be the case, though note that there is a bug posted about this:

It looks like calling glfwPollEvents() before you need to use glfwGetFramebufferSize might resolve this.