Use OpenGL window flag and switch to "fake" fullscreen mode

The OpenGL flag is required when using SDL2 on Windows. Fake fullscreen
works much better on modern monitors and systems with multiple monitors.
This commit is contained in:
Stefanos A. 2013-09-27 18:57:05 +02:00
parent 5df5447ff9
commit 56d7e4e564

View file

@ -24,11 +24,14 @@ namespace OpenTK.Platform.SDL2
static Sdl2KeyMap map = new Sdl2KeyMap(); static Sdl2KeyMap map = new Sdl2KeyMap();
public Sdl2NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device) public Sdl2NativeWindow(int x, int y, int width, int height,
string title, GameWindowFlags options, DisplayDevice device)
{ {
var bounds = device.Bounds; var bounds = device.Bounds;
var flags = TranslateFlags(options); var flags = TranslateFlags(options);
IntPtr handle = SDL.SDL_CreateWindow(title, bounds.Left + x, bounds.Right + y, width, height, flags); flags |= SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL;
flags |= SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE;
IntPtr handle = SDL.SDL_CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
window = new Sdl2WindowInfo(handle, null); window = new Sdl2WindowInfo(handle, null);
keyboard.Description = "Standard Windows keyboard"; keyboard.Description = "Standard Windows keyboard";
@ -53,7 +56,7 @@ namespace OpenTK.Platform.SDL2
switch (flags) switch (flags)
{ {
case GameWindowFlags.Fullscreen: case GameWindowFlags.Fullscreen:
return SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN; return SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
default: default:
return (SDL.SDL_WindowFlags)0; return (SDL.SDL_WindowFlags)0;
@ -131,6 +134,13 @@ namespace OpenTK.Platform.SDL2
} }
} }
void DestroyWindow()
{
exists = false;
SDL.SDL_DestroyWindow(window.Handle);
window.Handle = IntPtr.Zero;
}
#endregion #endregion
#region INativeWindow Members #region INativeWindow Members
@ -225,9 +235,7 @@ namespace OpenTK.Platform.SDL2
Closing(this, close_args); Closing(this, close_args);
if (!close_args.Cancel) if (!close_args.Cancel)
{ {
exists = false; DestroyWindow();
SDL.SDL_DestroyWindow(window.Handle);
window.Handle = IntPtr.Zero;
} }
break; break;
@ -360,9 +368,12 @@ namespace OpenTK.Platform.SDL2
switch (value) switch (value)
{ {
case WindowState.Fullscreen: case WindowState.Fullscreen:
if (SDL.SDL_SetWindowFullscreen(window.Handle, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN) < 0) if (SDL.SDL_SetWindowFullscreen(window.Handle, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) < 0)
{ {
SDL.SDL_SetWindowFullscreen(window.Handle, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP); if (SDL.SDL_SetWindowFullscreen(window.Handle, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN) < 0)
{
Debug.Print("SDL2 failed to enter fullscreen mode: {0}", SDL.SDL_GetError());
}
} }
break; break;
@ -610,7 +621,10 @@ namespace OpenTK.Platform.SDL2
{ {
if (!disposed) if (!disposed)
{ {
Close(); if (Exists)
{
DestroyWindow();
}
} }
else else
{ {