getFullscreenModes()[0] is not guaranteed to be the desktop mode. There's getDesktopMode() for that.
Other than that, I see nothing wrong in your code. I guess we could make the error output more verbose, it doesn't help much.
Thanks!
I changed it to use getDesktopMode() and it gives the same error, unfortunately.
So I added a couple of lines to the SFML source, WindowImplWin32.cpp to print out a bit of info just to verify what options it's passing to the ChangeDisplaySettingsW() call and I get this as error output:
Failed to change display mode for fullscreen
More info:
width=1280 height=800 BitsPerPel=32 Fields=1c0000
which corresponds to the default desktop parameters Windows is using on my PC, and I guess the fields are just bits to tell ChangeDisplaySettingsW() which fields it's passing.
I'm reading the
Windows ChangeDisplaySettings() docs now to try and get an error code from the call. I'll update when/if I figure something out.
UPDATE: Ok, adding the frequency in the call to ChangeDisplaySettingsW() fixes the problem.
Well, sort of -- the call works and it opens fullscreen, but it's a borderless fullscreen window still on the desktop. Hard to explain, but most gamers and devs will know, i.e. hitting alt-tab takes you to the previous OS window with the game still visible in the background.
Whereas the "separate fullscreen" mode would take you to the previous OS window without the game visibile in the background.
Not a big deal. The main reason I'm looking into all this is that I still can't get vertical sync to work on my PC as I detailed in this post:
http://en.sfml-dev.org/forums/index.php?topic=19082.0I'll keep experimenting with this.
Here's the change I made to WindowImplWin32::switchToFullscreen() BTW
void WindowImplWin32::switchToFullscreen(const VideoMode& mode)
{
DEVMODE devMode;
devMode.dmSize = sizeof(devMode);
devMode.dmPelsWidth = mode.width;
devMode.dmPelsHeight = mode.height;
devMode.dmBitsPerPel = mode.bitsPerPixel;
//devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
// Also pass frequency
devMode.dmDisplayFrequency = 60;
devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
// Change Display and get error code if any
long code;
code = ChangeDisplaySettingsW(&devMode, CDS_FULLSCREEN);
// Apply fullscreen mode
if (
//ChangeDisplaySettingsW(&devMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL
code != DISP_CHANGE_SUCCESSFUL
)
{
err() << "Failed to change display mode for fullscreen" << std::endl;
err() << "More info:\n";
err() << " width=" << mode.width << " height=" << mode.height <<
" BitsPerPel=" << mode.bitsPerPixel << " Fields=" << std::hex <<
(devMode.dmFields) << std::endl;
switch(code) {
case DISP_CHANGE_SUCCESSFUL:
err() << " DISP_CHANGE_SUCCESSFUL\n"; break;
case DISP_CHANGE_BADDUALVIEW:
err() << " DISP_CHANGE_BADDUALVIEW\n"; break;
case DISP_CHANGE_BADFLAGS:
err() << " DISP_CHANGE_BADFLAGS\n"; break;
case DISP_CHANGE_BADMODE:
err() << " DISP_CHANGE_BADMODE\n"; break;
case DISP_CHANGE_BADPARAM:
err() << " DISP_CHANGE_BADPARAM\n"; break;
case DISP_CHANGE_FAILED:
err() << " DISP_CHANGE_FAILED\n"; break;
case DISP_CHANGE_NOTUPDATED:
err() << " DISP_CHANGE_NOTUPDATED\n"; break;
case DISP_CHANGE_RESTART:
err() << " DISP_CHANGE_RESTART\n"; break;
default:
err() << " unrecognized error...\n"; break;
}
return;
}
// Make the window flags compatible with fullscreen mode
SetWindowLongW(m_handle, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
SetWindowLongW(m_handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
// Resize the window so that it fits the entire screen
SetWindowPos(m_handle, HWND_TOP, 0, 0, mode.width, mode.height, SWP_FRAMECHANGED);
ShowWindow(m_handle, SW_SHOW);
// Set "this" as the current fullscreen window
fullscreenWindow = this;
}