-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
e0b1b01
to
410cfe9
Compare
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? codemodified @@ -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 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 |
Oh heck, must have happened a force push on the dev branch, ill fix this when i get home |
This PR appears to have merge conflicts. Please fix them! |
@AbnormalPoof There merge conflicts are fixed! |
Looks like NinjaMuffin internally made the same change independently from you. This PR is now redundant I guess. |
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:

after:

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