Bug - Picture is not centered (macOS)

40 views
Skip to first unread message

eric andrade

unread,
Oct 20, 2020, 8:35:07 PM10/20/20
to Haskell Gloss
Hi guys,

I'm running the code on macOS Catalia (10.15.6 (19G73)) and I've got the axis not centered when I run it. When I try to resize the screen it get's in the right place.

The sample code


Before resizing

After resizing



Adrian Sieber

unread,
Oct 22, 2020, 5:37:52 AM10/22/20
to Haskell Gloss
I'm running the code on macOS Catalia (10.15.6 (19G73)) and I've got the axis not centered when I run it. When I try to resize the screen it get's in the right place.

I think that's the same bug as I described in February: https://groups.google.com/u/0/g/haskell-gloss/c/iEZbzwpwvtA/m/HYad520oCgAJ. Unfortunately, I don't think I have even enough knowledge about the underlying building blocks to tackle this issue, yet solve it. I'd be extremely grateful, if someone from the community took a stab at solving it 🙇‍♂️.

Ben Lippmeier

unread,
Oct 25, 2020, 6:03:59 AM10/25/20
to haskel...@googlegroups.com, eric andrade
Hi, sorry I don’t have a Catalina install to test this on. The problem has been reported before, but I don’t think it was resolved.

I’m not able to upgrade to Catalina currently as I still need to run time native 32-bit applications for work. It’s a bit of a mess.

Someone on Catalina will need to do some debugging. I would start with writing a dead simple application using the GLFW and/or GLUT bindings to see if the resize events are coming out as they should. That should only take an hour or so for someone that already has a Catalina install.

Ben.





--
You received this message because you are subscribed to the Google Groups "Haskell Gloss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-glos...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-gloss/610581a2-b7e6-43ca-8d6e-668b66e26781n%40googlegroups.com.

Jonathan Merritt

unread,
Oct 26, 2020, 3:21:07 AM10/26/20
to haskel...@googlegroups.com
Hi,

I believe this is the classic "HiDPI problem". See here for a description:
    https://stackoverflow.com/questions/36672935/why-retina-screen-coordinate-value-is-twice-the-value-of-pixel-value
(Incidentally, why it corrects itself after a resize is a bit of a mystery to me. I suspect that perhaps GL.viewport isn't actually taking effect correctly... when I move GL.viewport to callbackDisplay or withModelView then the "correction" reverts.)

I think this can be corrected in the GLFW-b backend using getFramebufferSize:
  https://hackage.haskell.org/package/GLFW-b-3.3.0.0/docs/Graphics-UI-GLFW.html#v:getFramebufferSize
I'll have a go at fixing it using this operation to obtain the true frame buffer size, to confirm.

However, I'm not sure of any approach that will work for GLUT. Indeed, people using Python GLUT are recommending using a patched version of GLUT (ie. not the one included with MacOS itself), like this one:
  http://iihm.imag.fr/blanch/software/glut-macosx/
That doesn't look like a very friendly option.

Jonathan Merritt.


Jonathan Merritt

unread,
Oct 26, 2020, 3:46:25 AM10/26/20
to haskel...@googlegroups.com
Question on this: is the ExplicitBackend Cabal flag hooked up to anything? I can't find where it's acting on anything.

If I disable GLUT and enable GLFW, I get compilation errors (they seem to be ifdef'd in the wrong order in a few places). I might just expose some Internal modules for the purposes of exploring the current bug, so that I can access displayWithBackend.

Jonathan Merritt

unread,
Oct 26, 2020, 3:57:04 AM10/26/20
to haskel...@googlegroups.com
Oh gosh, I can get the GLFW backend to start, but the window closes and the app quits immediately. Perhaps GLFW has some additional problems. I think it's going to take longer than anticipated to investigate.

Jonathan Merritt

unread,
Oct 26, 2020, 4:44:32 AM10/26/20
to haskel...@googlegroups.com
OK, here's a branch where I've hacked (with abandon) to get gloss-hello to work correctly with GLFW:

Aside from some miscellaneous fixes for GLFW, the fix for the original issue is this: https://github.com/lancelet/gloss/blob/hidpi-fix/gloss/Graphics/Gloss/Internals/Interface/Backend/GLFW.hs#L260-L262

To run it (after checking out that branch):
  cp stack-8.6.yaml stack.yaml
  stack build --flag gloss:GLFW
  stack exec gloss-hello

However, it's not mergeable yet. The main thing to sort out is: how should the GLFW backend really work? I don't think it's currently hooked-in properly. What should a correct backend switch look like?

Anyway, I'm done for this evening. I'm interested in getting a fix merged properly, but I think it will take quite a bit more effort.

Jonathan Merritt

unread,
Oct 28, 2020, 2:48:26 AM10/28/20
to haskel...@googlegroups.com
OK, I think I've fixed the GLFW backend and addressed this bug to the point where I have a mergeable PR: https://github.com/benl23x5/gloss/pull/46

However, I would really appreciate testing! :-)

Samuel Gélineau

unread,
Mar 31, 2021, 5:19:03 PM3/31/21
to Haskell Gloss
On GLUT, the problem disappears if I remove the call to viewState_reshape from Graphics.Gloss.Internals.Interface.Game.handle_reshape. The Picture is still centered after I resize the window. So it looks like the default behaviour is already the one we want and that setting the viewport in viewState_reshape only makes things worse.
Reply all
Reply to author
Forward
0 new messages