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

Fix rendering for devices which has higher DPI #3522

Closed
wants to merge 1 commit into from

Conversation

NeeEoo
Copy link

@NeeEoo NeeEoo commented Oct 1, 2024

Does this PR close any issues? If so, link them below.

Briefly describe the issue(s) fixed.

This fixed the game looking low res for certain devices, that has a higher dpi monitor.
This might not fix windows, since windows requires SetProcessDPIAware() to be called.
And i don't use windows so i cant test if it fixes it for windows

Include any relevant screenshots or videos.

Before:
image

after:
image

Despite the images showing the openfl sprites, it applies to flixel too

@ninjamuffin99 ninjamuffin99 force-pushed the develop branch 2 times, most recently from e0b1b01 to 410cfe9 Compare October 4, 2024 01:25
@cyn0x8
Copy link
Contributor

cyn0x8 commented Oct 10, 2024

cant compile these changes sadly (due to reasons unrelated to the following code) so im not gonna pr to your fork

but on windows im guessing an implementation would be kinda like this?

code

modified source/Main.hx...

@@ -4,6 +4,7 @@ import flixel.FlxGame;
 import flixel.FlxState;
 import funkin.Preferences;
 import funkin.util.logging.CrashHandler;
+import funkin.util.DPIUtil;
 import funkin.ui.debug.MemoryCounter;
 import funkin.save.Save;
 import haxe.ui.Toolkit;
@@ -19,8 +20,8 @@ import openfl.net.NetStream;
  */
 class Main extends Sprite
 {
-  var gameWidth:Int = 1280; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom).
-  var gameHeight:Int = 720; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
+  public static var gameWidth:Int = 1280; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom).
+  public static var gameHeight:Int = 720; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
   var initialState:Class<FlxState> = funkin.InitState; // The FlxState the game starts with.
   var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions.
   var skipSplash:Bool = true; // Whether to skip the flixel splash screen that appears in release mode.
@@ -34,6 +35,8 @@ class Main extends Sprite
     CrashHandler.initialize();
     CrashHandler.queryStatus();
 
+    DPIUtil.fixWindowSize();
+
     Lib.current.addChild(new Main());
   }
 

new file source/funkin/util/DPIUtil.hx

package funkin.util;

import lime.app.Application;
import lime.system.Display;
import lime.system.System;
import lime.ui.Window;
import flixel.FlxG;
import Main;

#if windows
@:cppInclude("windows.h")
@:cppInclude("winuser.h")
#end

/**
 * Utilities for DPI awareness.
 */
class DPIUtil
{
  public static function __init__():Void
  {
    #if windows
    registerDPIAwareness();
    #end
  }

  #if windows
  @:functionCode("SetProcessDPIAware();")
  public static function registerDPIAwareness():Void {}
  #end

  public static var dpiScale(get, never):Float;
  private static function get_dpiScale():Float
  {
    var display:Display = System.getDisplay(0);
    if (display != null)
    {
      return display.dpi / (
        #if windows 96
        #elseif mac 72
        #elseif linux 96
        #elseif ios 163
        #elseif android 160
        #else 96
        #end
      );
    }

    return 1;
  }

  public static function fixWindowSize():Void
  {
    #if desktop // (windows?)
    var window:Window = Application.current.window;
    var prevWidth:Int = window.width;
    var prevHeight:Int = window.height;
    window.width = Std.int(Main.gameWidth * dpiScale);
    window.height = Std.int(Main.gameHeight * dpiScale);
    window.x += Std.int((prevWidth - window.width) / 2);
    window.y += Std.int((prevHeight - window.height) / 2);
    #end
  }
}

however this makes the window smaller the higher resolution you have.... cuz the game will become literally 1280x720 regardless of your scaling

i added some code to compensate, and while it works for the game content (tested in a basic flixel project), it seems stuff based on window size isnt scaled right

for example im using a 1.5x scale on my monitor and so the flixel mouse is 2/3 the size it should be

@NeeEoo
Copy link
Author

NeeEoo commented Jan 3, 2025

Oh heck, must have happened a force push on the dev branch, ill fix this when i get home

@EliteMasterEric EliteMasterEric added the status: pending triage Awaiting review. label Jan 17, 2025
@Hundrec Hundrec added type: minor bug Involves a minor bug or issue. size: medium A medium pull request with 100 or fewer changes. pr: haxe PR modifies game code. size: small A small pull request with 10 or fewer changes. and removed size: medium A medium pull request with 100 or fewer changes. labels Jan 22, 2025
@AbnormalPoof AbnormalPoof added the topic: polish Involves minor polish to the UI or gameplay. label Jan 22, 2025
@AbnormalPoof
Copy link
Collaborator

This PR appears to have merge conflicts. Please fix them!

@AbnormalPoof AbnormalPoof added status: needs revision Cannot be approved because it is awaiting some work by the contributor. and removed status: pending triage Awaiting review. topic: polish Involves minor polish to the UI or gameplay. labels Jan 22, 2025
@NeeEoo NeeEoo closed this Jan 25, 2025
@NeeEoo NeeEoo reopened this Jan 25, 2025
@NeeEoo
Copy link
Author

NeeEoo commented Jan 25, 2025

@AbnormalPoof There merge conflicts are fixed!

@Hundrec Hundrec added status: pending triage Awaiting review. and removed status: needs revision Cannot be approved because it is awaiting some work by the contributor. labels Jan 25, 2025
@AbnormalPoof AbnormalPoof added the topic: polish Involves minor polish to the UI or gameplay. label Jan 25, 2025
@EliteMasterEric
Copy link
Member

Looks like NinjaMuffin internally made the same change independently from you. This PR is now redundant I guess.

@EliteMasterEric EliteMasterEric added status: rejected Issue did not pass review or PR cannot be approved. and removed status: pending triage Awaiting review. labels Feb 14, 2025
@EliteMasterEric EliteMasterEric added this to the 0.6.0 (Pit Stop 2) milestone Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: haxe PR modifies game code. size: small A small pull request with 10 or fewer changes. status: rejected Issue did not pass review or PR cannot be approved. topic: polish Involves minor polish to the UI or gameplay. type: minor bug Involves a minor bug or issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants