Skip to content

[Bug] ImGui Main Viewport Resolution and HiDPI Issue #24

@GreenComfyTea

Description

@GreenComfyTea

Describe The Bug

In some game configuration cases ImGui viewport resolution doesn't match the game resolution, causing ImGui to either be cut off in the middle of the screen or go outside of the game.

Little dive into my configuration before showcasing the issue:
I have a 1080p 60Hz 96DPI (x1 scale) main display with the game + 2 additional displays on each side (both 1366x768 60Hz x1 scale).

On my Nvidia card to get higher in-game resolution options available than the max display resolution I use DSR (Dynamic Super Resolution). Since the game has awful Anti-Aliasing options, downscaling from super resolution is a recommended way to achieve AA on powerful systems, so I am not discarding this edge case, as other power gamers may be using DSR as well.

Screenshot 1

image

Screenshot 2

image

To better visualize the actual viewport, I draw a giant half-transparent red rectangle with 5000x5000 size.

var backgroundDrawList = ImGui.GetBackgroundDrawList();

var position = new Vector2(0, 0);
var size = new Vector2(5000, 5000);

backgroundDrawList.AddRectFilled(position, position + size, 0xAA0000FF);

On the screenshots pay attention where actual Tea Overlay window is on the screen and where it is on small viewport visualization in the debugger.

Fullscreen works because it actually changes the display resolution:

  1. Fullscreen + 1280x720 Game Resolution -> OK;
Screenshot

image

  1. Fullscreen + 1920x1080 Game Resolution -> OK;
Screenshot

image

  1. Fullscreen + 2880x1620 Game Resolution -> OK;
Screenshot

image

Windowed Mode:

  1. Windowed Mode + 1280x720 Game Resolution -> OK;
Screenshot

image

  1. Windowed Mode + 1920x1080 Game Resolution -> 19 pixels are cut off from the bottom;
Screenshot

image

  1. Windowed Mode + 2880x1620 Game Resolution -> ???;
Screenshot

image

Borderless Window:

  1. Borderless Window + 1280x720 Game Resolution -> ImGui goes beyond the game;
Screenshot

image

  1. Borderless Window + 1920x1080 Game Resolution -> OK;
Screenshot

image

  1. Borderless Window + 2880x1620 Game Resolution -> ImGui is cut mid-screen;
Screenshot

image

Video

I have been able to partially fix the viewport with this code:

ImGui.GetMainViewport().WorkSize = new Vector2(2880f, 1620f);
ImGui.GetMainViewport().Size = new Vector2(2880f, 1620f);

But unfortunately it only affects where ImGui is allowed to draw windows and stuff. Mouse still behaves incorrectly as if the mouse viewport was scaled down and desynchronizes with the actual cursor.

Video

Playing around with ImGui.GetIO().DisplaySize and ImGui.GetIO().DisplayFramebufferScale gave no results. ImGui.GetDrawData().ScaleClipRects() causes a crash.

I don't if it is relevant, but in Borderless Window the game doesn't launch the game window at the target display resolution, but instead launches the window with the game resolution -> then ImGui gets initialized in 1080p -> then GPU driver scales down the whole window to fit into the target display. (In contrast to when Resolution may refer to 3D Rendering Resolution, often present as % Scaling in modern games).

As a result, we end up with target resolution being smaller than the resolution used by the framebuffer. This sounds a lot like how Hi-DPI Retina screens work. where there is a pixel ratio of 2.0 between the size of the framebuffer and the size of the application window.
Reference 1
Reference 2

So I assume Hi-DPI display will have a similar issue as well.

As a side note, ImGui looks readable only in 1080p. On higher resolutions (in other words, on higher DPI displays) it will look tiny and on smaller resolutions it will look big. SPL probably should scale it's main ImGui window automatically or provide for end users a way to scale it manually. But going further, perhaps, SPL should automatically handle default scaling for plugins as well?

To Reproduce

  1. Launch the game in Borderless Window or Windowed Mode with a resolution that is different from the display resolution.

Expected Behavior

ImGui viewport should match the game resolution.

Priority

Suggested P2 Priority. The issue alters the indented functionality of SPL and plugins under some circumstances.

PC Specs

Show/Hide
  • Motherboard: Asus ROG Strix Z390-H Gaming
  • CPU: Intel Core i9-9900k
  • RAM: 32 GB 3200MHz
  • GPU: Nvidia GeForce RTX 3090 Ti
  • System and Game SSD: Samsung SSD 970 EVO Plus NVMe M.2 1TB
  • Plugin Repo SSD: Western Digital Blue SATA M.2 2280 2TB

Environment

Show/Hide
  • OS: Window 10 Enterprise Version 22H2 (OS Build 19045.3996)
  • Monster Hunter: World: v15.21.00
  • SharpPluginLoader: pre-v0.0.4.0 (bea1094)
  • Nvidia Drivers: v551.52

Game Display Settings

Show/Hide
  • DirectX 12 API: On
  • Screen Mode**: ~~~**
  • Resolution Settings**: ~~~**
  • Aspect Ratio: Wide (16:9)
  • Nvidia DLSS: Off
  • FidelityFX CAS + Upscaling: Off
  • Frame Rate: No Limit
  • V-Sync: On

Game Advanced Graphics Settings

Show/Hide
  • Image Quality: High
  • Texture Quality: High Resolution Texture Pack
  • Ambient Occlusion: High
  • Volume Rendering Quality: Highest
  • Shadow Quality: High
  • Capsule AO: On
  • Contact Shadows: On
  • Anti-Aliasing: Off
  • LOD Bias: High
  • Max LOD Level: No Limit
  • Foliage Sway: On
  • Subsurface Scattering: On
  • Screen Space Reflection: On
  • Anisotropic Filtering: Highest
  • Water Reflection: On
  • Snow Quality: High
  • SH Diffuse Quality: High
  • Dynamic Range: 64-bit
  • Motion Blur: On
  • DOF (Depth of Field): On
  • Vignette Effects: Normal
  • Z-Prepass: On

Mods and External Tools:

Show/Hide

Additional Context

Plugin Repo

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingnativeThis issue is related to native code

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions