Windows / OpenGL / fullscreen

When I change display mode with (SDL_OPENGL | SDL_FULLSCREEN), and then quit the program, all other windows in the desktop have been moved or resized. This only happens with the OPENGL -flag.

Is there a way to fix this? Just a minor point, perhaps, but I find it irritating.

I dug a bit into the SDL source, and noticed that for OpenGL, ChangeDisplaySettings() is used instead of DirectDraw to set the fullscreen mode. I guess that is the problem. Is there a good reason for this? Using IDirectDraw2_SetDisplayMode() would seem to be cleaner way to achieve the same effect.

And then there is this comment in SDL_dx5video.c:

/* Set fullscreen mode if appropriate.
Ugh, since our list of valid video modes comes from
the DirectX driver, we may not actually be able to
change to the desired resolution here.
FIXME: Should we do a closest match?
*/
if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {

If we get the modes from DirectX driver, why not use it to change them?

Have you tried other window manager?On Fri, Aug 30, 2002 at 10:51:09AM -0400, gtxayf1q001 at sneakemail.com wrote:

When I change display mode with (SDL_OPENGL | SDL_FULLSCREEN), and then quit
the program, all other windows in the desktop have been moved or resized.
This only happens with the OPENGL -flag.


http://decopter.sf.net - free unrealistic helicopter simulator

When I change display mode with (SDL_OPENGL | SDL_FULLSCREEN), and then quit the program, all other windows in the desktop have been moved or resized. This only happens with the OPENGL -flag.

Is there a way to fix this? Just a minor point, perhaps, but I find it irritating.

I dug a bit into the SDL source, and noticed that for OpenGL, ChangeDisplaySettings() is used instead of DirectDraw to set the fullscreen mode. I guess that is the problem. Is there a good reason for this? Using IDirectDraw2_SetDisplayMode() would seem to be cleaner way to achieve the same effect.

Yes, there is. According to Microsoft, using DirectX in combination
with OpenGL may fail in unexpected ways, and on several video cards it
does. Only GDI calls may be used with OpenGL. Painful, but true.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

I dug a bit into the SDL source, and noticed that for
OpenGL, ChangeDisplaySettings() is used instead of
DirectDraw to set the fullscreen mode. I guess that is
the problem. Is there a good reason for this? Using
IDirectDraw2_SetDisplayMode() would seem to be cleaner
way to achieve the same effect.

Yes, there is. According to Microsoft, using DirectX in combination
with OpenGL may fail in unexpected ways, and on several video cards it
does. Only GDI calls may be used with OpenGL. Painful, but true.

Thanks for the info. Painful indeed, I have used that
before, tested on few systems, and it worked perfectly.
It never occurred to me that there might be a problem.

No way to avoid the window relocating effect in “OpenGL-
fullscreen”? To a perfectionist used to better, it somehow
gives the impression of 2nd quality software. Irrational,
I know. :wink:

No way to avoid the window relocating effect in “OpenGL-
fullscreen”?

Not that I know of, but if somebody does, please let me know.
I’ll revisit this for the next generation SDL API… it may be that all
the video cards available when that’s ready will work well with DirectX.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

No way to avoid the window relocating effect in “OpenGL-
fullscreen”?

Not that I know of, but if somebody does, please let me know.
I’ll revisit this for the next generation SDL API… it may be that all
the video cards available when that’s ready will work well with DirectX.

Fair enough.

Feeling somewhat stubborn today, I “fixed” the problem by
hacking the library into saving positions of all desktop
windows at startup and WM_ACTIVATE. And then restoring
them. Works for me, and the couple of systems I could
test it with, although possibly not good idea universally.

Hmm… I was actually about to suggest that… any chance you could post
a patch?

Best wishes,

-LorenOn Sat, 2002-08-31 at 14:01, gtxayf1q001 at sneakemail.com wrote:

No way to avoid the window relocating effect in “OpenGL-
fullscreen”?

Not that I know of, but if somebody does, please let me know.
I’ll revisit this for the next generation SDL API… it may be that all
the video cards available when that’s ready will work well with DirectX.

Fair enough.

Feeling somewhat stubborn today, I “fixed” the problem by
hacking the library into saving positions of all desktop
windows at startup and WM_ACTIVATE. And then restoring
them. Works for me, and the couple of systems I could
test it with, although possibly not good idea universally.

No way to avoid the window relocating effect in “OpenGL-
fullscreen”?

Feeling somewhat stubborn today, I “fixed” the problem by
hacking the library into saving positions of all desktop
windows at startup and WM_ACTIVATE. And then restoring
them. Works for me, and the couple of systems I could
test it with, although possibly not good idea universally.

Hmm… I was actually about to suggest that… any chance you could post
a patch?

Sure. Someone who knows a bit more about WIN32 or SDL can
improve on this, perhaps. And point out potential problems.

SDL_dx5video.c:

#ifdef WIN32_DESKTOP_SAVE

#define MAX_WINDOWS 256
static int num_windows = 0;
static HWND window_hwnd[MAX_WINDOWS];
static WINDOWPLACEMENT placement[MAX_WINDOWS];

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
if(num_windows < MAX_WINDOWS)
{
if(hwnd != SDL_Window && IsWindowVisible(hwnd))
{
placement[num_windows].length = sizeof(WINDOWPLACEMENT);
if(GetWindowPlacement(hwnd, &placement[num_windows]) != 0)
{
window_hwnd[num_windows] = hwnd;
num_windows++;
}
}
}
return TRUE;
}

void save_desktop(void)
{
num_windows = 0;
EnumWindows(EnumWindowsProc, 0);
}

void restore_desktop(void)
{
/* Okay, this may look strange. I don’t like it either.
We are always calling this right after ChangeDisplaySettings(),
and it seems that the mode change may still be taking place,
as sometimes the windows aren’t restored. The more delay I
put, the more likely it is that it will work. But if there
is much delay, the window movement is clearly visible. And
delay isn’t very robust way to do anything. But I couldn’t
find a reliable way to check if it worked or not.
*/

restore_desktop1();
SDL_Delay(500);
restore_desktop1();
}

void restore_desktop1(void)
{
int i;
for(i = 0; i < num_windows; i++)
{
HWND hwnd = window_hwnd[i];
if(IsWindow(hwnd))
{
SetWindowPlacement(hwnd, &placement[i]);
}
}
}

#endif /* WIN32_DESKTOP_SAVE */

DX5_SetVideoMode()

#ifndef NO_CHANGEDISPLAYSETTINGS
/* Unset any previous OpenGL fullscreen mode */
if ( (current->flags & (SDL_OPENGL|SDL_FULLSCREEN)) ==
(SDL_OPENGL|SDL_FULLSCREEN) ) {
ChangeDisplaySettings(NULL, 0);
#ifdef WIN32_DESKTOP_SAVE
restore_desktop();
#endif
}
#endif

#ifndef NO_CHANGEDISPLAYSETTINGS
/* Set fullscreen mode if appropriate.
Ugh, since our list of valid video modes comes from
the DirectX driver, we may not actually be able to
change to the desired resolution here.
FIXME: Should we do a closest match?
*/

#ifdef WIN32_DESKTOP_SAVE
save_desktop();
#endif

DX5_VideoQuit()

ChangeDisplaySettings(NULL, 0);
#ifdef WIN32_DESKTOP_SAVE
restore_desktop();
#endif

SDL_sysevents.c:

static void SDL_RestoreGameMode(void)
{
#ifndef NO_CHANGEDISPLAYSETTINGS
#ifdef WIN32_DESKTOP_SAVE
save_desktop();
#endif
ShowWindow(SDL_Window, SW_RESTORE);
ChangeDisplaySettings(&SDL_fullscreen_mode, CDS_FULLSCREEN);
#endif
}
static void SDL_RestoreDesktopMode(void)
{
#ifndef NO_CHANGEDISPLAYSETTINGS
ShowWindow(SDL_Window, SW_MINIMIZE);
ChangeDisplaySettings(NULL, 0);
#ifdef WIN32_DESKTOP_SAVE
restore_desktop();
#endif
#endif
}