From 2a604bbaf19942211ca74df8181775cb7ef803b8 Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Wed, 8 Jan 2025 09:40:35 +0000 Subject: [PATCH] Change: Alter init of OpenTK, to attempt to workaround HiDPI issues on Win32 https://github.com/leezer3/OpenBVE/issues/1104 https://github.com/leezer3/OpenBVE/issues/1066 --- source/ObjectViewer/ProgramS.cs | 29 +++++++++++++++++------------ source/RouteViewer/ProgramR.cs | 18 +++++++++++++++--- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/source/ObjectViewer/ProgramS.cs b/source/ObjectViewer/ProgramS.cs index 70ca05960..0db266d3c 100644 --- a/source/ObjectViewer/ProgramS.cs +++ b/source/ObjectViewer/ProgramS.cs @@ -75,7 +75,22 @@ internal static void Main(string[] args) CurrentRoute = new CurrentRoute(CurrentHost, Renderer); Options.LoadOptions(); - Renderer = new NewRenderer(CurrentHost, Interface.CurrentOptions, FileSystem); + // n.b. Init the toolkit before the renderer + var options = new ToolkitOptions + { + Backend = PlatformBackend.PreferX11, + }; + + if (CurrentHost.Platform == HostPlatform.MicrosoftWindows) + { + // We're managing our own DPI + options.EnableHighResolution = false; + SetProcessDPIAware(); + } + + Toolkit.Init(options); + + Renderer = new NewRenderer(CurrentHost, Interface.CurrentOptions, FileSystem); TrainManager = new TrainManager(CurrentHost, Renderer, Interface.CurrentOptions, FileSystem); @@ -145,17 +160,7 @@ internal static void Main(string[] args) } } - var options = new ToolkitOptions - { - Backend = PlatformBackend.PreferX11 - }; - - if (CurrentHost.Platform == HostPlatform.MicrosoftWindows) - { - // Tell Windows that the main game is managing it's own DPI - SetProcessDPIAware(); - } - Toolkit.Init(options); + // --- load language --- string folder = Program.FileSystem.GetDataFolder("Languages"); Translations.LoadLanguageFiles(folder); diff --git a/source/RouteViewer/ProgramR.cs b/source/RouteViewer/ProgramR.cs index 989fb3345..1a8c78fde 100644 --- a/source/RouteViewer/ProgramR.cs +++ b/source/RouteViewer/ProgramR.cs @@ -77,6 +77,21 @@ internal static void Main(string[] args) FileSystem.CreateFileSystem(); Sounds = new Sounds(CurrentHost); Options.LoadOptions(); + // n.b. Init the toolkit before the renderer + var options = new ToolkitOptions + { + Backend = PlatformBackend.PreferX11, + }; + + if (CurrentHost.Platform == HostPlatform.MicrosoftWindows) + { + // We're managing our own DPI + options.EnableHighResolution = false; + SetProcessDPIAware(); + } + + Toolkit.Init(options); + Renderer = new NewRenderer(CurrentHost, Interface.CurrentOptions, FileSystem); CurrentRoute = new CurrentRoute(CurrentHost, Renderer); TrainManager = new TrainManager(CurrentHost, Renderer, Interface.CurrentOptions, FileSystem); @@ -156,9 +171,6 @@ internal static void Main(string[] args) SetProcessDPIAware(); } - var options = new ToolkitOptions(); - options.Backend = PlatformBackend.PreferX11; - Toolkit.Init(options); string folder = Program.FileSystem.GetDataFolder("Languages"); Translations.LoadLanguageFiles(folder); Interface.CurrentOptions.ObjectOptimizationBasicThreshold = 1000;