Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screen size different from render size on 4k monitor #20

Open
wilsonk opened this issue Oct 8, 2024 · 12 comments
Open

Screen size different from render size on 4k monitor #20

wilsonk opened this issue Oct 8, 2024 · 12 comments

Comments

@wilsonk
Copy link
Contributor

wilsonk commented Oct 8, 2024

Sorry if I am bothering you with this stuff :) I am getting different sizes on almost all examples between render and screen while using a 4k monitor on linux.

So I end up seeing this type of thing where the port is different from the full window size. It is very apparent on the pong game, as I can't see both players and all edges (this is with a very low level card, but I doubt that matters):

Screenshot_2024-10-08_12-57-43

Seems to work fine with MacOS on the same 4k monitor, however. I would test on windows, but the build is failing with glfw3_mt.lib missing with mingw64?

@redthing1
Copy link
Member

that's probably DPI scaling? there's fields on the core to adjust it. I thought I had fixed it, but I guess not?

It would be helpful if you could give more information about your monitor resolution and scaling, etc., and whether you're using Xorg or Wayland?

I have tested on a hidpi scaled Xorg Linux and also on macs, both of which seem to work.

Clearly I overlooked something, let's try to figure it out.

@wilsonk
Copy link
Contributor Author

wilsonk commented Oct 8, 2024

Xorg no Wayland here.

xrdb -query | grep dpi
shows
Xft.dpi = 136

xdpyinfo | grep resolution
shows
resolution: 96x96 dots per inch

xrandr | grep -w connected
shows
HDMI-A-0 connected 3840x2160+0+0 (normal left inverted right x axis y axis) 708mm x 399mm

No scaling on Xfce settings (just 1x in other words). Any other info you might need? I think I had a similar issue with dvui (a zig based immediate mode ui), but I can't remember off hand how we fixed it, darnit.

@redthing1
Copy link
Member

Thanks for the details. Yeah, I think I see the issue, it's fractional scaling. Right now I assumed all scaling would be integer. But there's not really anything preventing fractional scaling from working either, so it should be an easy fix.

@redthing1
Copy link
Member

@wilsonk can you please set this in your entry point before reng initializes, and send all the logs? I want to see what happens with the window size and scaling calculations.

Core.log.verbosity = Verbosity.debug_;

@wilsonk
Copy link
Contributor Author

wilsonk commented Oct 10, 2024

Hmm, I have tried putting that statement at every single line of the quickshd example to no avail. Then I tried changing core.d initializer at line 103 to .debug_, recompiled the lib and the example with --force...no change, only INFO debug informaiton is produced. I literally don't know what else to even try, sorry?

@redthing1
Copy link
Member

can you go to core and window and just add a bunch of logs to see what it's detecting as the scale DPI, window size, screen size, then go to scene and print out the render target size
I don't have time to do it myself

@redthing1
Copy link
Member

redthing1 commented Oct 12, 2024

ok, so I should clarify some things. there are some overlapping things that can be confusing:

in raylib we have:

int GetScreenWidth (); // Get current screen width
int GetScreenHeight (); // Get current screen height
int GetRenderWidth (); // Get current render width (it considers HiDPI)
int GetRenderHeight (); // Get current render height (it considers HiDPI)
  • how reng works, is that each scene renders to an internal render target, then that render target is drawn to the screen.
  • if HIDPI is working properly, we should expect GetRenderWidth to return the framebuffer size (which is DPI aware, so it would be multiplied by the scale factor).
  • on the other hand the screen coordinates remain the same regardless of DPI, so they are scaled to the framebuffer
  • how reng handles this is that HIDPI is used to oversample the render framebuffer, so that when it's drawn to screen coordinates we don't scale up a lowres texture but rather match or exceed the target framebuffer rectangle size

please see:

@redthing1
Copy link
Member

redthing1 commented Oct 12, 2024

It would be really helpful if you could figure out how to share your reng logs. Here are mine, on a HIDPI macOS display, for example:

note the following:

  • screen size 960x540
  • but reported render with by GetRenderWidth is double that due to 2x scaling
  • and a 2x oversample factor makes the final render resolution 3840x2160, which is drawn to a 960x540 screen space rect
[info/13:03:18] initializing rengfx core
INFO: Initializing raylib 5.0
INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 1728 x 1117
INFO:     > Screen size:  960 x 540
INFO:     > Render size:  960 x 540
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 43
INFO: GL: OpenGL device information:
INFO:     > Vendor:   Apple
INFO:     > Renderer: Apple M2 Max
INFO:     > Version:  4.1 Metal - 88.1
INFO:     > GLSL:     4.10
INFO: GL: VAO extension detected, VAO functions loaded successfully
INFO: GL: NPOT textures extension detected, full NPOT textures supported
INFO: GL: DXT compressed textures supported
INFO: PLATFORM: DESKTOP (GLFW): Initialized successfully
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: TIMER: Target time per frame: 16.667 milliseconds
[info/13:03:18] updating render resolution to Vector2(3840, 2160) (oversample 2)
INFO: TEXTURE: [ID 3] Texture loaded successfully (960x540 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Depth renderbuffer loaded successfully (32 bits)
INFO: FBO: [ID 1] Framebuffer object created successfully
[info/13:03:18] debugger info: ui_bounds=Rectangle(0, 0, 960, 540), resolution=Vector2(3840, 2160)
[info/13:03:18] initializing game
INFO: TEXTURE: [ID 4] Texture loaded successfully (3840x2160 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 2] Depth renderbuffer loaded successfully (32 bits)
INFO: FBO: [ID 2] Framebuffer object created successfully
INFO: FILEIO: [./res/SourceSansPro-Regular.ttf] File loaded successfully
INFO: TEXTURE: [ID 5] Texture loaded successfully (256x256 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Data loaded successfully (16 pixel size | 95 glyphs)
INFO: NUKLEAR: Initialized GUI
[info/13:03:18] status: ready.
[info/13:03:19] gracefully exiting
INFO: FBO: [ID 1] Unloaded framebuffer from VRAM (GPU)
INFO: FBO: [ID 2] Unloaded framebuffer from VRAM (GPU)
INFO: TEXTURE: [ID 2] Unloaded texture data from VRAM (GPU)
INFO: SHADER: [ID 3] Default shader unloaded successfully
INFO: TEXTURE: [ID 1] Default texture unloaded successfully
INFO: Window closed successfully

@redthing1
Copy link
Member

please check the dpi branch

@wilsonk
Copy link
Contributor Author

wilsonk commented Oct 12, 2024

Strange, can you not see this INFO output in the screen capture at the top? I can if I zoom in a bit...but anyways, here it is in a clearer form:

[info/14:18:43] initializing rengfx core
INFO: Initializing raylib 5.0
INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 3840 x 2160
INFO:     > Screen size:  960 x 540
INFO:     > Render size:  1320 x 742
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 235
INFO: GL: OpenGL device information:
INFO:     > Vendor:   AMD
INFO:     > Renderer: AMD Radeon R9 380 Series (radeonsi, tonga, LLVM 18.1.8, DRM 3.54, 6.6.52-1-lts)
INFO:     > Version:  4.6 (Core Profile) Mesa 24.2.3-arch1.1
INFO:     > GLSL:     4.60
INFO: GL: VAO extension detected, VAO functions loaded successfully
INFO: GL: NPOT textures extension detected, full NPOT textures supported
INFO: GL: DXT compressed textures supported
INFO: GL: ETC2/EAC compressed textures supported
INFO: PLATFORM: DESKTOP (GLFW): Initialized successfully
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: TIMER: Target time per frame: 16.667 milliseconds
[info/14:18:44] updating render resolution to Vector2(1320, 742) (oversample 1) -> screen rect Rectangle(0, 0, 960, 540)
INFO: TEXTURE: [ID 3] Texture loaded successfully (960x540 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Depth renderbuffer loaded successfully (32 bits)
INFO: FBO: [ID 1] Framebuffer object created successfully
[info/14:18:44] debugger info: ui_bounds=Rectangle(0, 0, 960, 540), resolution=Vector2(1320, 742)
[info/14:18:44] initializing game
INFO: TEXTURE: [ID 4] Texture loaded successfully (960x540 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 2] Depth renderbuffer loaded successfully (32 bits)
INFO: FBO: [ID 2] Framebuffer object created successfully
INFO: VAO: [ID 2] Mesh uploaded successfully to VRAM (GPU)
[info/14:18:44] reloading shader: (vs: , fs: ../content/shader/cross_stitch.frag)
INFO: FILEIO: [../content/shader/cross_stitch.frag] Text file loaded successfully
INFO: SHADER: [ID 4] Fragment shader compiled successfully
INFO: SHADER: [ID 5] Program shader loaded successfully
[info/14:18:44] reloading shader: (vs: , fs: ../content/shader/chromatic_aberration.frag)
INFO: FILEIO: [../content/shader/chromatic_aberration.frag] Text file loaded successfully
INFO: SHADER: [ID 6] Fragment shader compiled successfully
INFO: SHADER: [ID 7] Program shader loaded successfully
INFO: TEXTURE: [ID 5] Texture loaded successfully (960x540 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 3] Depth renderbuffer loaded successfully (32 bits)
INFO: FBO: [ID 3] Framebuffer object created successfully
[info/14:18:44] reloading shader: (vs: , fs: ../content/shader/cross_stitch.frag)
INFO: FILEIO: [../content/shader/cross_stitch.frag] Text file loaded successfully
INFO: SHADER: [ID 8] Fragment shader compiled successfully
INFO: SHADER: [ID 9] Program shader loaded successfully
[info/14:18:44] reloading shader: (vs: , fs: ../content/shader/chromatic_aberration.frag)
INFO: FILEIO: [../content/shader/chromatic_aberration.frag] Text file loaded successfully
INFO: SHADER: [ID 10] Fragment shader compiled successfully
INFO: SHADER: [ID 11] Program shader loaded successfully
INFO: FBO: [ID 1] Unloaded framebuffer from VRAM (GPU)
INFO: VAO: [ID 2] Unloaded vertex array data from VRAM (GPU)
INFO: MODEL: Unloaded model (and meshes) from RAM and VRAM
INFO: FBO: [ID 3] Unloaded framebuffer from VRAM (GPU)
INFO: FBO: [ID 2] Unloaded framebuffer from VRAM (GPU)
INFO: TEXTURE: [ID 2] Unloaded texture data from VRAM (GPU)
INFO: SHADER: [ID 3] Default shader unloaded successfully
INFO: TEXTURE: [ID 1] Default texture unloaded successfully
INFO: Window closed successfully

@redthing1
Copy link
Member

based on that, it seems both render size and screen size look correct no?

one thing that might be useful: in the core find where it draws the scene render target, then ensure it's drawing it to the correct screen bounds: in screen space the rect should still be 960x540
maybe make a scene that just draws rectangles

also please check that the render target itself is the right shape

there's also a possibility that the lack of fractional scaling is on raylib's side, but I'll have to double check

@wilsonk
Copy link
Contributor Author

wilsonk commented Oct 13, 2024

Yeah it looks like the render and screen sizes are right and it looks like the calculation for fractional scaling is being done correctly for the window.dpi_scale variable (=1.375), as 1320/960 is 1.375. So now I guess dpi_scale just needs to be applied everywhere that it would be necessary? I guess...?

It seems like the nuidemo should be grabbing the dpi_scale and applying it correctly but that doesn't seem to be the case...argh!

Here is what David and I did on dvui, but that was with SDL:
david-vanderson/dvui#17

Looks like things might be even worse on windows?:
david-vanderson/dvui#150

According to raysan5 scaling is pretty broken as of April:
raysan5/raylib#157 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants