From e8f7eeb5dcdd2296e5341a86f95734c1717fcbc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Blissing?= Date: Thu, 30 Nov 2017 12:47:57 +0100 Subject: [PATCH 1/4] Removed unnecessary define in FileUtils The define of _WIN32_WINNT was added to handle an error case from MinGW ,as described in commit 712ca432196cd797cc3c265adb2847465551461f This was later giving warnings and thus undefined for MinGW by commit 3bf6fb1778687c45d389b91675b55f709ef1f67b Since the two operations cancel each other out, they should be removed. --- src/osgDB/FileNameUtils.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/osgDB/FileNameUtils.cpp b/src/osgDB/FileNameUtils.cpp index 383638e93..34b740a86 100644 --- a/src/osgDB/FileNameUtils.cpp +++ b/src/osgDB/FileNameUtils.cpp @@ -19,9 +19,6 @@ #include #ifdef WIN32 -#if !defined(__MINGW32__) - #define _WIN32_WINNT 0x0500 -#endif #include #endif From 09eefd79736cde57ed108c781259e9c201805746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Blissing?= Date: Thu, 30 Nov 2017 12:53:24 +0100 Subject: [PATCH 2/4] Added script to identify Windows version Added script to identify the Windows version used to compile the source. Currently the windows version for Windows NT is hard coded into the source. By running this CMake script the _WIN32_WINNT preprocessor variable gets set to the corresponding windows version. --- CMakeLists.txt | 4 ++++ CMakeModules/OsgDetermineWinVersion.cmake | 22 +++++++++++++++++++ .../osgViewer/api/Win32/GraphicsHandleWin32 | 11 +++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 CMakeModules/OsgDetermineWinVersion.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f05d9f6ec..2bb3196b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -344,6 +344,10 @@ ENDIF() IF(WIN32 AND NOT ANDROID) + # Check window version + INCLUDE (OsgDetermineWinVersion) + get_WIN32_WINNT(WIN_VERSION) + ADD_DEFINITIONS(-D_WIN32_WINNT=${WIN_VERSION}) IF(MSVC) # This option is to enable the /MP switch for Visual Studio 2005 and above compilers diff --git a/CMakeModules/OsgDetermineWinVersion.cmake b/CMakeModules/OsgDetermineWinVersion.cmake new file mode 100644 index 000000000..dbf9554a9 --- /dev/null +++ b/CMakeModules/OsgDetermineWinVersion.cmake @@ -0,0 +1,22 @@ +# - If Windows is used, this script sets the variable WIN32_WINNT to the corresponding windows version + +if (WIN32) + message(STATUS "Checking windows version...") + macro(get_WIN32_WINNT version) + if (CMAKE_SYSTEM_VERSION) + set(ver ${CMAKE_SYSTEM_VERSION}) + string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver}) + string(REGEX MATCH "^([0-9]+)" verMajor ${ver}) + # Check for Windows 10, b/c we'll need to convert to hex 'A'. + if ("${verMajor}" MATCHES "10") + set(verMajor "A") + string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver}) + endif ("${verMajor}" MATCHES "10") + # Remove all remaining '.' characters. + string(REPLACE "." "" ver ${ver}) + # Prepend each digit with a zero. + string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver}) + set(${version} "0x${ver}") + endif(CMAKE_SYSTEM_VERSION) + endmacro(get_WIN32_WINNT) +endif(WIN32) \ No newline at end of file diff --git a/include/osgViewer/api/Win32/GraphicsHandleWin32 b/include/osgViewer/api/Win32/GraphicsHandleWin32 index f6ac8fa28..5959e6bf2 100644 --- a/include/osgViewer/api/Win32/GraphicsHandleWin32 +++ b/include/osgViewer/api/Win32/GraphicsHandleWin32 @@ -16,8 +16,17 @@ #include +// Fallback if not correctly detected in CMake macro #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0500 +//#define _WIN32_WINNT 0x0A00 // Windows 10 +//#define _WIN32_WINNT 0x0603 // Windows 8.1 +//#define _WIN32_WINNT 0x0602 // Windows 8 +//#define _WIN32_WINNT 0x0601 // Windows 7 +//#define _WIN32_WINNT 0x0600 // Windows Server 2008 +//#define _WIN32_WINNT 0x0600 // Windows Vista +//#define _WIN32_WINNT 0x0502 // Windows Server 2003 with SP1, Windows XP with SP2 +//#define _WIN32_WINNT 0x0501 // Windows Server 2003, Windows XP +#define _WIN32_WINNT 0x0500 // Windows NT #endif #include From 9fac39c5e09cc6157fe77dca8810b329ad8e43f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Blissing?= Date: Thu, 30 Nov 2017 13:00:54 +0100 Subject: [PATCH 3/4] Applications declared DPI-aware in the Windows environment Applications that run on a Windows computer with desktop scaling enabled gets scaled incorrectly since windows assumes that applications are DPI-unaware unless declared otherwise. This change declares the application DPI-aware, thus not automatically scaled by the operating system. The corresponding library call requires Windows 8.1 or later. --- src/osgViewer/GraphicsWindowWin32.cpp | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index b1cb6ce9d..6905a8856 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -144,6 +144,26 @@ static CloseTouchInputHandleFunc *closeTouchInputHandleFunc = NULL; static GetTouchInputInfoFunc *getTouchInputInfoFunc = NULL; static GetPointerTypeFunc *getPointerTypeFunc = NULL; +// DPI Awareness +#if(WINVER >= 0x0603) + +#ifndef DPI_ENUMS_DECLARED + +typedef enum PROCESS_DPI_AWARENESS { + PROCESS_DPI_UNAWARE = 0, + PROCESS_SYSTEM_DPI_AWARE = 1, + PROCESS_PER_MONITOR_DPI_AWARE = 2 +} PROCESS_DPI_AWARENESS; + +#endif // DPI_ENUMS_DECLARED + +typedef +BOOL +(WINAPI SetProcessDpiAwarenessFunc( + PROCESS_DPI_AWARENESS dpi_awareness)); + +static SetProcessDpiAwarenessFunc *setProcessDpiAwareness = NULL; +#endif @@ -765,6 +785,21 @@ Win32WindowingSystem::Win32WindowingSystem() FreeLibrary( hModule); } } + + +#if(WINVER >= 0x0603) + // For Windows 8.1 and higher + // + // Per monitor DPI aware.This app checks for the DPI when it is created and adjusts the scale factor + // whenever the DPI changes.These applications are not automatically scaled by the system. + HMODULE hModuleShore = LoadLibrary("Shcore"); + if (hModuleShore) { + setProcessDpiAwareness = (SetProcessDpiAwarenessFunc *) GetProcAddress(hModuleShore, "SetProcessDpiAwareness"); + if (setProcessDpiAwareness) { + (*setProcessDpiAwareness)(PROCESS_DPI_AWARENESS::PROCESS_PER_MONITOR_DPI_AWARE); + } + } +#endif } Win32WindowingSystem::~Win32WindowingSystem() From b909ac2d9510e9b23945cfd109e690dea488c894 Mon Sep 17 00:00:00 2001 From: OpenSceneGraph git repository Date: Thu, 30 Nov 2017 14:12:05 +0000 Subject: [PATCH 4/4] Added return to last line --- CMakeModules/OsgDetermineWinVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeModules/OsgDetermineWinVersion.cmake b/CMakeModules/OsgDetermineWinVersion.cmake index dbf9554a9..9d7a0619d 100644 --- a/CMakeModules/OsgDetermineWinVersion.cmake +++ b/CMakeModules/OsgDetermineWinVersion.cmake @@ -19,4 +19,4 @@ if (WIN32) set(${version} "0x${ver}") endif(CMAKE_SYSTEM_VERSION) endmacro(get_WIN32_WINNT) -endif(WIN32) \ No newline at end of file +endif(WIN32)