From 4a3e91928515b69ca33715ae947f1c17eb5fb7ab Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Thu, 18 Jul 2019 11:14:31 +1000 Subject: [PATCH 1/2] window mode improvements *support borderless with original glut *check game mode support for actual requested display mode --- source/plugins/Render/dllmain.cpp | 39 ++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/source/plugins/Render/dllmain.cpp b/source/plugins/Render/dllmain.cpp index e135be3..2ebabc3 100644 --- a/source/plugins/Render/dllmain.cpp +++ b/source/plugins/Render/dllmain.cpp @@ -3,39 +3,52 @@ #pragma comment(lib, "detours.lib") #include #include +#include #include #include int hookedCreateWindow(const char* title, void(__cdecl* exit_function)(int)) { - if (nDisplay == 1) + if (nDisplay == 1) // borderless fullscreen { *fullScreenFlag = 0; + int nWidth = glutGet(GLUT_SCREEN_WIDTH); + int nHeight = glutGet(GLUT_SCREEN_HEIGHT); + glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_BORDERLESS); - glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH), glutGet(GLUT_SCREEN_HEIGHT)); + glutInitWindowSize(nWidth, nHeight); glutInitWindowPosition(0, 0); glutCreateWindow(title); - printf("[Render Manager] Borderless mode.\n"); + + // support borderless mode even with original copy of glut + HDC hDev = wglGetCurrentDC(); // get handle to current opengl device context + HWND hWnd = WindowFromDC(hDev); // convert it to a window handle + SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP); // set popup style (no border) + SetWindowPos(hWnd, HWND_TOP, 0, 0, nWidth, nHeight, 0); // adjust position to apply new style + + printf("[Render Manager] Borderless mode.\n"); } - else if (nDisplay == 2) + else if (nDisplay == 2) // fullscreen { - // Crashes, no idea why yet + char GameModeString[24]; + sprintf_s(GameModeString, sizeof(GameModeString), "%dx%d:%d@%d", nWidth, nHeight, nBitDepth, nRefreshRate); + glutGameModeString(GameModeString); + if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) { - char GameModeString[24]; - sprintf_s(GameModeString, sizeof(GameModeString),"%dx%d:%d@%d", nWidth, nHeight, nBitDepth ,nRefreshRate); - printf("[Render Manager] Game Mode supported and enabled in replacement of Fullscreen.\n"); + printf("[Render Manager] Game mode (exclusive fullscreen) enabled.\n"); printf(GameModeString); printf("\n"); - glutGameModeString(GameModeString); glutEnterGameMode(); } else { - *fullScreenFlag = 1; - glutCreateWindow(title); - printf("[Render Manager] Fullscreen enabled.\n"); + printf("[Render Manager] Requested display mode not supported. Using non-exclusive fullscreen instead.\n"); + printf(GameModeString); + printf("\n"); + *fullScreenFlag = 1; + glutCreateWindow(title); } } - else + else // windowed { *fullScreenFlag = 0; glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); From 0f5601e1614977c6baf84e351b306682f6fae103 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Fri, 19 Jul 2019 13:51:33 +1000 Subject: [PATCH 2/2] borderless mode: fix mouse interaction for freeglut (checks client area position before using the WS_POPUP workaround for original glut) --- source/plugins/Render/dllmain.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/source/plugins/Render/dllmain.cpp b/source/plugins/Render/dllmain.cpp index 2ebabc3..68f1943 100644 --- a/source/plugins/Render/dllmain.cpp +++ b/source/plugins/Render/dllmain.cpp @@ -14,17 +14,22 @@ int hookedCreateWindow(const char* title, void(__cdecl* exit_function)(int)) *fullScreenFlag = 0; int nWidth = glutGet(GLUT_SCREEN_WIDTH); int nHeight = glutGet(GLUT_SCREEN_HEIGHT); + int nX = 0; + int nY = 0; glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_BORDERLESS); glutInitWindowSize(nWidth, nHeight); - glutInitWindowPosition(0, 0); + glutInitWindowPosition(nX, nY); glutCreateWindow(title); - // support borderless mode even with original copy of glut - HDC hDev = wglGetCurrentDC(); // get handle to current opengl device context - HWND hWnd = WindowFromDC(hDev); // convert it to a window handle - SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP); // set popup style (no border) - SetWindowPos(hWnd, HWND_TOP, 0, 0, nWidth, nHeight, 0); // adjust position to apply new style + if (glutGet(GLUT_WINDOW_X) != nX || glutGet(GLUT_WINDOW_Y) != nY) // if not in borderless mode (top left of client area isn't top left of window position) + { + // support borderless mode even with original copy of glut + HDC hDev = wglGetCurrentDC(); // get handle to current opengl device context + HWND hWnd = WindowFromDC(hDev); // convert it to a window handle + SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP); // set popup style (no border) + SetWindowPos(hWnd, HWND_TOP, 0, 0, nWidth, nHeight, 0); // adjust position to apply new style + } printf("[Render Manager] Borderless mode.\n"); }