Use OpenGL window flag and switch to "fake" fullscreen mode
authorStefanos A. <stapostol@gmail.com>
Fri, 27 Sep 2013 16:57:05 +0000 (18:57 +0200)
committerStefanos A. <stapostol@gmail.com>
Fri, 27 Sep 2013 16:57:05 +0000 (18:57 +0200)
The OpenGL flag is required when using SDL2 on Windows. Fake fullscreen
works much better on modern monitors and systems with multiple monitors.

Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs

index eadffe9dc90ba69a387e27348774a0f4fde08aa0..6ce8b0a4bbdd172a22ddb44d36beec6f36f5cc6a 100644 (file)
@@ -24,11 +24,14 @@ namespace OpenTK.Platform.SDL2
 
         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 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);
 
             keyboard.Description = "Standard Windows keyboard";
@@ -53,7 +56,7 @@ namespace OpenTK.Platform.SDL2
             switch (flags)
             {
                 case GameWindowFlags.Fullscreen:
-                    return SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
+                    return SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
                 
                 default:
                     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
 
         #region INativeWindow Members
@@ -225,9 +235,7 @@ namespace OpenTK.Platform.SDL2
                         Closing(this, close_args);
                         if (!close_args.Cancel)
                         {
-                            exists = false;
-                            SDL.SDL_DestroyWindow(window.Handle);
-                            window.Handle = IntPtr.Zero;
+                            DestroyWindow();
                         }
                         break;
 
@@ -360,9 +368,12 @@ namespace OpenTK.Platform.SDL2
                 switch (value)
                 {
                     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;
 
@@ -610,7 +621,10 @@ namespace OpenTK.Platform.SDL2
             {
                 if (!disposed)
                 {
-                    Close();
+                    if (Exists)
+                    {
+                        DestroyWindow();
+                    }
                 }
                 else
                 {