LWJGL3 HiDPI support

Started by arcnor, October 09, 2015, 00:16:37

Previous topic - Next topic

arcnor

I've read that LWJGL3 has HiDPI support since 3.0.0a. I'm working on a backend for GDX, and so far, my app always gets drawn on the bottom-left corner of my window, and I'd like to know if anyone has a solution for it.

The issue happens when I change my window from a non-HiDPI screen to a HiDPI one on OSX, at least. With LWJGL2, a refresh happens and the framebuffer gets multiplied (or that's what I guess it's happening) but with LWJGL3 I get a corner or sometimes even the non-HiDPI resolution until I resize the window.

What's the proper way of specifying a HiDPI mode for LWJGL3/GLFW? Also, how can I "detect" that my window has changed to a different density monitor, and trigger an event in that case (i.e. to replicate what LWJGL2 seems to be doing)?

Thanks!

arcnor

A bit more info... The exact behavior seems to be:

When on a HiDPI screen:

  • 1. You get the bottom-left corner of the screen
  • 2. When you move the window, the content gets magically resized to the full window, but looking pixelated (non-HiDPI)
  • 3. When you resize the window, the content goes back to the bottom-left corner

Please excuse me if you think this is related to my own code, but in that case, I'd like to know how to deal with this problem, if possible :D.

Thanks again!

arcnor

In the end, judicious use of glfwGetFramebufferSize() & glfwSetFramebufferSizeCallback() (http://www.glfw.org/docs/latest/window.html#window_fbsize) has fixed my issue, although I still can't explain why moving the window changed the resolution, but I'm sure it will be a similar issue.

Hopefully this will be useful to somebody :)

spasi

Quote from: arcnor on October 09, 2015, 06:23:09In the end, judicious use of glfwGetFramebufferSize() & glfwSetFramebufferSizeCallback() (http://www.glfw.org/docs/latest/window.html#window_fbsize) has fixed my issue

Indeed, this is the correct way to handle HiDPI (the LWJGL demos use it too). The window size callback returns the window size in screen coordinates, whereas the framebuffer size callback returns the window size in pixels. On non-HiDPI displays screen coordinates and pixels will have an 1:1 ratio, but on HiDPI the number of pixels per screen coordinate will be higher.

Quote from: arcnor on October 09, 2015, 06:23:09although I still can't explain why moving the window changed the resolution

This is probably OSX-specific behavior. It might also have to do with whether you call glViewport explictly or not.

arcnor

It might be OSX specific behavior. I found a bug report from years ago (https://github.com/glfw/glfw/issues/49) from someone that experienced the same (moving the window changed the rendering, which is odd).

In my case, while using the right framebuffer & window sizes the problem never shows again, but I just hope this won't manifest itself as a different problem in the future :)