mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-20 04:34:48 +00:00
Merge pull request #961 from BeamNG/fix_opengl_fullscreen
Fix OpenGL fullscreen on win32
This commit is contained in:
commit
7184e36928
|
|
@ -64,6 +64,19 @@ static bool isScreenSaverRunning()
|
|||
return sreensaver;
|
||||
}
|
||||
|
||||
DISPLAY_DEVICE GetPrimaryDevice()
|
||||
{
|
||||
int index = 0;
|
||||
DISPLAY_DEVICE dd;
|
||||
dd.cb = sizeof(DISPLAY_DEVICE);
|
||||
|
||||
while (EnumDisplayDevices(NULL, index++, &dd, 0))
|
||||
{
|
||||
if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) return dd;
|
||||
}
|
||||
return dd;
|
||||
}
|
||||
|
||||
Win32Window::Win32Window(): mMouseLockPosition(0,0),
|
||||
mShouldLockMouse(false),
|
||||
mMouseLocked(false),
|
||||
|
|
@ -125,9 +138,10 @@ const GFXVideoMode & Win32Window::getVideoMode()
|
|||
|
||||
void Win32Window::setVideoMode( const GFXVideoMode &mode )
|
||||
{
|
||||
bool needCurtain = (mVideoMode.fullScreen != mode.fullScreen);
|
||||
bool needCurtain = (mVideoMode.fullScreen != mode.fullScreen);
|
||||
static bool first_load = true;
|
||||
|
||||
if(needCurtain)
|
||||
if(needCurtain)
|
||||
{
|
||||
Con::errorf("Win32Window::setVideoMode - invoking curtain");
|
||||
mOwningManager->lowerCurtain();
|
||||
|
|
@ -150,10 +164,33 @@ void Win32Window::setVideoMode( const GFXVideoMode &mode )
|
|||
|
||||
// Set our window to have the right style based on the mode
|
||||
if(mode.fullScreen && !Platform::getWebDeployment() && !mOffscreenRender)
|
||||
{
|
||||
SetWindowLong( getHWND(), GWL_STYLE, WS_POPUP);
|
||||
SetWindowPos( getHWND(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
|
||||
|
||||
{
|
||||
WINDOWPLACEMENT wplacement = { sizeof(wplacement) };
|
||||
DWORD dwStyle = GetWindowLong(getHWND(), GWL_STYLE);
|
||||
MONITORINFO mi = { sizeof(mi) };
|
||||
|
||||
if (GetWindowPlacement(getHWND(), &wplacement) && GetMonitorInfo(MonitorFromWindow(getHWND(), MONITOR_DEFAULTTOPRIMARY), &mi))
|
||||
{
|
||||
DISPLAY_DEVICE dd = GetPrimaryDevice();
|
||||
DEVMODE dv;
|
||||
ZeroMemory(&dv, sizeof(dv));
|
||||
dv.dmSize = sizeof(DEVMODE);
|
||||
EnumDisplaySettings(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dv);
|
||||
dv.dmPelsWidth = mode.resolution.x;
|
||||
dv.dmPelsHeight = mode.resolution.y;
|
||||
dv.dmBitsPerPel = mode.bitDepth;
|
||||
dv.dmDisplayFrequency = mode.refreshRate;
|
||||
dv.dmFields = (DM_PELSWIDTH | DM_PELSHEIGHT);
|
||||
ChangeDisplaySettings(&dv, CDS_FULLSCREEN);
|
||||
SetWindowLong(getHWND(), GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW);
|
||||
SetWindowPos(getHWND(), HWND_TOP,
|
||||
mi.rcMonitor.left,
|
||||
mi.rcMonitor.top,
|
||||
mi.rcMonitor.right - mi.rcMonitor.left,
|
||||
mi.rcMonitor.bottom - mi.rcMonitor.top,
|
||||
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
||||
}
|
||||
|
||||
if(mDisplayWindow)
|
||||
ShowWindow(getHWND(), SW_SHOWNORMAL);
|
||||
|
||||
|
|
@ -172,7 +209,12 @@ void Win32Window::setVideoMode( const GFXVideoMode &mode )
|
|||
}
|
||||
else
|
||||
{
|
||||
// Reset device *first*, so that when we call setSize() and let it
|
||||
if (!first_load)
|
||||
ChangeDisplaySettings(NULL, 0);
|
||||
|
||||
first_load = false;
|
||||
|
||||
// Reset device *first*, so that when we call setSize() and let it
|
||||
// access the monitor settings, it won't end up with our fullscreen
|
||||
// geometry that is just about to change.
|
||||
|
||||
|
|
@ -1166,4 +1208,4 @@ const UTF16 *Win32Window::getWindowClassName()
|
|||
const UTF16 *Win32Window::getCurtainWindowClassName()
|
||||
{
|
||||
return _CurtainWindowClassName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue