kaveh808 / kons-9

Common Lisp 3D Graphics Project
MIT License
582 stars 33 forks source link

Menu issue on 4k monitors. #125

Open aykaramba opened 2 years ago

aykaramba commented 2 years ago

Opening up issue as per request in this ticket: https://github.com/kaveh808/kons-9/discussions/118#discussioncomment-3844190

PROBLEM: Menu boxes render properly but the text is offset by varying amounts on 4k mintor as per screenshot:

194181411-88334ee9-92af-452f-a7ad-75a7b478f355

The issue is still in the latest git pull of the test-engine branch as of posting of this ticket.

System info: Linux 5.10.0-18-amd64 https://github.com/kaveh808/kons-9/pull/1 SMP Debian 5.10.140-1 (2022-09-02) x86_64 GNU/Linux (Debian 11)

When I run this: (glfw:get-monitor-content-scale (glfw:get-primary-monitor))

The result is this: (1.1458334 1.1458334 )

kaveh808 commented 2 years ago

Thanks for the testing @aykaramba

In the file kons-9/src/graphics/glfw/minimal-ui.lisp, in the function show-window at the bottom of the file is this code:

          (setf (monitor-scale *drawing-settings*)
                (first (glfw:get-monitor-content-scale (glfw:get-primary-monitor))))

Try two things and see how they affect the font placement. Change the above expression to the following:

1)

          (setf (monitor-scale *drawing-settings*) 1)

2)

          (setf (monitor-scale *drawing-settings*) 2)
aykaramba commented 2 years ago

Well, that worked.

Details:

1) (setf (monitor-scale drawing-settings) 1) produces this:

good

2) (setf (monitor-scale drawing-settings) 2) produces this:

bad

For me, this is good enough, I can use this to keep playing around and testing. If you would like to have me do any further testing, please let me know. More than happy to help.

kaveh808 commented 2 years ago

Hmm, I wonder if your monitor is an odd case, or whether I should set the monitor scale to the floor of the specified value...

As far as more testing, please feel free to try out the scenes in demo.lisp and try out variations of your own to see if (a) you get any cool results we can add to our demos, or (b) you find bugs.

lukego commented 2 years ago

My 4K monitor is setup for 200% (2.0) scaling. The main UI text looks right but the menu draws in the wrong place:

https://user-images.githubusercontent.com/13791/195351519-0a145c0e-2b99-49ab-9b4b-391743756d4e.mp4

In principle I can work around this by changing the scaling factor to 1 though in practice that makes the text too small for me to read :)

How is scaling supposed to happen in the UI? Do all text operations need to be manually scaled? I tried adding some multiply-by-scaling-factor operations to ui-widgets.lisp but didn't stumble upon the right correction.

kaveh808 commented 2 years ago

I don't take the monitor-size into account for the GUI, but the text engine does, so this is probably the cause.

And yet everything looks correct on my MacOS external monitor (scale = 1) and my laptop display (scale = 2).

I'll reopen the issue...

awolven commented 2 years ago

you should be able to set the framebuffer-scale variable to whatever is returned by "get monitor content scale" and that should be a good foundation for tackling the problem. I think it has to be done before ensure-font is called.

On Wed, Oct 12, 2022 at 2:25 PM Kaveh Kardan @.***> wrote:

Reopened #125 https://github.com/kaveh808/kons-9/issues/125.

— Reply to this email directly, view it on GitHub https://github.com/kaveh808/kons-9/issues/125#event-7574700437, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABGMMIRVH7MSROLOKR6NFDWC4GBRANCNFSM6AAAAAARB253B4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

awolven commented 2 years ago

right now it just assumes #+darwin and #-darwin framebuffer-scale 2 and 1 respectively, which is severe ignorance apparently.

On Wed, Oct 12, 2022 at 2:50 PM Andrew Wolven @.***> wrote:

you should be able to set the framebuffer-scale variable to whatever is returned by "get monitor content scale" and that should be a good foundation for tackling the problem. I think it has to be done before ensure-font is called.

On Wed, Oct 12, 2022 at 2:25 PM Kaveh Kardan @.***> wrote:

Reopened #125 https://github.com/kaveh808/kons-9/issues/125.

— Reply to this email directly, view it on GitHub https://github.com/kaveh808/kons-9/issues/125#event-7574700437, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABGMMIRVH7MSROLOKR6NFDWC4GBRANCNFSM6AAAAAARB253B4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

lukego commented 1 year ago

@awolven I can't find the variable *framebuffer-scale* anywhere. We do have a slot monitor-scale but that seems to be initialized to 1 on all platforms so I guess that's not it. What am I missing? (Apologies for the slow followup.)

kaveh808 commented 1 year ago

@lukego In glfw-gui.lisp we do the following to get the monitor scale:

          ;; assume monitor scale is same in x and y, just use first value
          ;; also assume we are running on the "primary" monitor
          ;; use FLOOR due to bug encountered with user's 4K monitor setting of 1.1458334
          (setf (monitor-scale *drawing-settings*)
                (floor (first (glfw:get-monitor-content-scale (glfw:get-primary-monitor)))))
awolven commented 1 year ago

I don't think monitor content scale is supposed to necessarily be an integer.

On Mon, Nov 14, 2022 at 2:58 PM Kaveh Kardan @.***> wrote:

@lukego https://github.com/lukego In glfw-gui.lisp we do the following to get the monitor scale:

      ;; assume monitor scale is same in x and y, just use first value
      ;; also assume we are running on the "primary" monitor
      ;; use FLOOR due to bug encountered with user's 4K monitor setting of 1.1458334
      (setf (monitor-scale *drawing-settings*)
            (floor (first (glfw:get-monitor-content-scale (glfw:get-primary-monitor)))))

— Reply to this email directly, view it on GitHub https://github.com/kaveh808/kons-9/issues/125#issuecomment-1314370046, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABGMML75WWROQ7I7KTTH63WIKRYFANCNFSM6AAAAAARB253B4 . You are receiving this because you were mentioned.Message ID: @.***>

kaveh808 commented 1 year ago

@awolven You are probably correct. I recall setting it to 1.0 fixed someone's scaling problem a while back and made the assumption it should be a whole number.

On my available displays, the scalings are 1.0 and 2.0, so I can't test fractional values. If anyone does test this, please let me know.

lukego commented 1 year ago

Just a ping that this problem still persists. I can't see the menu items when I use kons-9:

image

I tried to fix this a way back but didn't identify the right scaling parameter to change. If someone knows how to make the fix that would be great because it probably affects quite a few potential users.

kaveh808 commented 1 year ago

The relevant code is in src/graphics/glfw/glfw-gui.lisp

          ;; assume monitor scale is same in x and y, just use first value
          ;; also assume we are running on the "primary" monitor
          ;; use FLOOR due to bug encountered with user's 4K monitor setting of 1.1458334
          (setf (monitor-scale *drawing-settings*)
                (floor (first (glfw:get-monitor-content-scale (glfw:get-primary-monitor)))))

Hope this helps. Let me know how it goes.

bpostlethwaite commented 1 year ago

I had missing text and then stumbled on this issue. I have a laptop with a HiRes screen and 2x scaling.

(monitor-scale *drawing-settings*)
;; returns 2.0

returns 2.0 as expected. However this results in text that is drawn off-screen, so invisible: image

Forcing (setf (monitor-scale *drawing-settings*) 1.0) draws the text in the correct place, but the text is very small

image

I'm not quite sure how to debug this further, perhaps as @kaveh808 suggested

I don't take the monitor-size into account for the GUI, but the text engine does, so this is probably the cause.

I'm on Ubuntu Linux fwiw

kaveh808 commented 1 year ago

If someone with access to a 4K monitor could look into this, I would appreciate it.