diff --git a/.gitignore b/.gitignore index f8055b0719..04c35efa25 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ bin .vscode /tools/mikktspace/out *.exe +.DS_store \ No newline at end of file diff --git a/h3d/Engine.hx b/h3d/Engine.hx index e07ba63838..757963d4f2 100644 --- a/h3d/Engine.hx +++ b/h3d/Engine.hx @@ -280,7 +280,14 @@ class Engine { if( height < 32 ) height = 32; this.width = width; this.height = height; - if( !driver.isDisposed() ) driver.resize(width, height); + + // Set the driver size to actual pixel width + // (same as window size on normal displays, differs when high DPI is enabled) + var r = window.windowToPixelRatio; + var pw = Std.int(width / r); + var ph = Std.int(height / r); + + if( !driver.isDisposed() ) driver.resize(pw, ph); } public function begin() { diff --git a/hxd/System.hl.hx b/hxd/System.hl.hx index 98cb74c0f4..76b376553c 100644 --- a/hxd/System.hl.hx +++ b/hxd/System.hl.hx @@ -97,6 +97,7 @@ class System { var size = haxe.macro.Compiler.getDefine("windowSize"); var title = haxe.macro.Compiler.getDefine("windowTitle"); var fixed = haxe.macro.Compiler.getDefine("windowFixed") == "1"; + var highDPI = haxe.macro.Compiler.getDefine("highDPI") == "1"; if( title == null ) title = ""; if( size != null ) { @@ -108,10 +109,10 @@ class System { #if hlsdl sdl.Sdl.init(); @:privateAccess Window.initChars(); - @:privateAccess Window.inst = new Window(title, width, height, fixed); + @:privateAccess Window.inst = new Window(title, width, height, fixed, highDPI); init(); #elseif hldx - @:privateAccess Window.inst = new Window(title, width, height, fixed); + @:privateAccess Window.inst = new Window(title, width, height, fixed, highDPI); init(); #else @:privateAccess Window.inst = new Window(title, width, height); diff --git a/hxd/Window.hl.hx b/hxd/Window.hl.hx index 41ee95dfb7..246f1a5fe2 100644 --- a/hxd/Window.hl.hx +++ b/hxd/Window.hl.hx @@ -26,6 +26,8 @@ class Window { public var width(get, never) : Int; public var height(get, never) : Int; + public var windowToPixelRatio(get, never) : Float; + public var mouseX(get, never) : Int; public var mouseY(get, never) : Int; public var mouseLock(get, set) : Bool; @@ -50,13 +52,16 @@ class Window { static inline var TOUCH_SCALE = #if (hl_ver >= version("1.12.0")) 10000 #else 100 #end; #end - function new(title:String, width:Int, height:Int, fixed:Bool = false) { + function new(title:String, width:Int, height:Int, fixed:Bool = false, highDPI = false) { this.windowWidth = width; this.windowHeight = height; eventTargets = new List(); resizeEvents = new List(); #if hlsdl - final sdlFlags = if (!fixed) sdl.Window.SDL_WINDOW_SHOWN | sdl.Window.SDL_WINDOW_RESIZABLE else sdl.Window.SDL_WINDOW_SHOWN; + var sdlFlags = if (!fixed) sdl.Window.SDL_WINDOW_SHOWN | sdl.Window.SDL_WINDOW_RESIZABLE else sdl.Window.SDL_WINDOW_SHOWN; + if (highDPI) { + sdlFlags |= sdl.Window.SDL_WINDOW_ALLOW_HIGHDPI; + } window = new sdl.Window(title, width, height, sdl.Window.SDL_WINDOWPOS_CENTERED, sdl.Window.SDL_WINDOWPOS_CENTERED, sdlFlags); #elseif hldx final dxFlags = if (!fixed) dx.Window.RESIZABLE else 0; @@ -133,6 +138,10 @@ class Window { function get_height() : Int { return windowHeight; } + + function get_windowToPixelRatio() : Float { + return window.windowToPixelRatio; + } function get_mouseLock() : Bool { return false; diff --git a/hxd/Window.hx b/hxd/Window.hx index 79e5db182b..c71dc533eb 100644 --- a/hxd/Window.hx +++ b/hxd/Window.hx @@ -14,6 +14,8 @@ class Window { public var width(get, never) : Int; public var height(get, never) : Int; + public var windowToPixelRatio(get, never) : Float; + public var mouseX(get, never) : Int; public var mouseY(get, never) : Int; public var mouseLock(get, set) : Bool; @@ -95,6 +97,10 @@ class Window { return 0; } + function get_windowToPixelRatio() : Float { + return 0.0; + } + function get_mouseLock() : Bool { return false; } diff --git a/hxd/Window.js.hx b/hxd/Window.js.hx index 086815c923..ed048d7746 100644 --- a/hxd/Window.js.hx +++ b/hxd/Window.js.hx @@ -14,6 +14,8 @@ class Window { public var width(get, never) : Int; public var height(get, never) : Int; + public var windowToPixelRatio(get, never) : Float; + public var mouseX(get, never) : Int; public var mouseY(get, never) : Int; public var mouseLock(get, set) : Bool; @@ -201,6 +203,10 @@ class Window { return Math.round(canvasPos.height * getPixelRatio()); } + function get_windowToPixelRatio() { + return 1.0; + } + function get_mouseX() { return Math.round((curMouseX - canvasPos.left) * getPixelRatio()); }