diff --git a/SMCode/SM.Base/SMRenderer.cs b/SMCode/SM.Base/SMRenderer.cs index 204a508..8e6b524 100644 --- a/SMCode/SM.Base/SMRenderer.cs +++ b/SMCode/SM.Base/SMRenderer.cs @@ -43,6 +43,11 @@ namespace SM.Base /// public static MaterialShader DefaultMaterialShader; + /// + /// The default render pipeline. + /// + public static RenderPipeline DefaultRenderPipeline; + /// /// Shows more information onto the log system. /// diff --git a/SMCode/SM.Base/Window/GLWindow.cs b/SMCode/SM.Base/Window/GLWindow.cs index 6e75aa2..c4b49ad 100644 --- a/SMCode/SM.Base/Window/GLWindow.cs +++ b/SMCode/SM.Base/Window/GLWindow.cs @@ -3,6 +3,7 @@ using System; using System.ComponentModel; using System.Diagnostics; +using System.Drawing.Text; using System.Threading; using System.Windows.Forms; using OpenTK; @@ -23,10 +24,14 @@ namespace SM.Base.Window /// public class GLWindow : GameWindow, IGenericWindow { + private Vector2 _flagWindowPos; private Vector2 _flagWindowSize; + private Thread _fixedUpdateThread; private WindowFlags _windowFlags; + private DisplayResolution _normalResolution; + private DisplayResolution _fullscreenResolution; /// @@ -45,6 +50,7 @@ namespace SM.Base.Window public bool DrawWhileUnfocused { get; set; } = true; /// public bool UpdateWhileUnfocused { get; set; } = false; + /// public Vector2 WindowSize { get; set; } /// @@ -70,8 +76,9 @@ namespace SM.Base.Window { if (_windowFlags != value) { + WindowFlags oldV = _windowFlags; _windowFlags = value; - ChangeWindowFlag(value); + ChangeWindowFlag(value, oldV); } } } @@ -93,14 +100,15 @@ namespace SM.Base.Window /// /// public GLWindow(int width, int height, string title, WindowFlags flags, VSyncMode vSync = VSyncMode.On) : - base(width, height, default, title, (GameWindowFlags) flags, DisplayDevice.Default, + base(width, height, default, title, GameWindowFlags.Default, DisplayDevice.Default, GLSettings.ForcedVersion.MajorVersion, GLSettings.ForcedVersion.MinorVersion, GraphicsContextFlags.Default) { VSync = vSync; - _flagWindowSize = new Vector2(width, height); - WindowFlags = flags; + + FocusedChanged += GLWindow_FocusedChanged; + _normalResolution = _fullscreenResolution = DisplayDevice.Default.SelectResolution(DisplayDevice.Default.Width, DisplayDevice.Default.Height, DisplayDevice.Default.BitsPerPixel, DisplayDevice.Default.RefreshRate); } @@ -125,8 +133,6 @@ namespace SM.Base.Window WindowCode.Resize(this); - if (WindowFlags == WindowFlags.Window) _flagWindowSize = WindowSize; - if (Loading) { Loading = false; @@ -217,6 +223,17 @@ namespace SM.Base.Window CurrentRenderPipeline = renderPipeline; } + /// + /// Changes the resolution in fullscreen mode. + /// Can be executed before changing to fullscreen, but with no effect until changed. + /// + /// The resolution you get from or + public void ChangeFullscreenResolution(DisplayResolution resolution) + { + _fullscreenResolution = resolution; + + if (_windowFlags == WindowFlags.ExclusiveFullscreen) ApplyFullscreenResolution(); + } /// /// Starts the fixed update loop. @@ -248,17 +265,48 @@ namespace SM.Base.Window } } - private void ChangeWindowFlag(WindowFlags newFlag) + private void GLWindow_FocusedChanged(object sender, EventArgs e) { + if (_windowFlags == WindowFlags.ExclusiveFullscreen) + { + if (!Focused) + { + DisplayDevice.Default.ChangeResolution(_normalResolution); + WindowState = WindowState.Minimized; + } + else + { + ApplyFullscreenResolution(); + } + } + + } + private void ChangeWindowFlag(WindowFlags newFlag, WindowFlags oldFlag) + { + if (oldFlag == WindowFlags.Window) + { + _flagWindowSize = WindowSize; + _flagWindowPos = new Vector2(X, Y); + } + switch (newFlag) { case WindowFlags.Window: + DisplayDevice.Default.ChangeResolution(_normalResolution); + WindowState = WindowState.Normal; Width = (int)_flagWindowSize.X; Height = (int)_flagWindowSize.Y; + X = (int) _flagWindowPos.X; + Y = (int) _flagWindowPos.Y; + WindowBorder = WindowBorder.Resizable; + + break; case WindowFlags.BorderlessWindow: + DisplayDevice.Default.ChangeResolution(_normalResolution); + WindowState = WindowState.Maximized; WindowBorder = WindowBorder.Hidden; X = Screen.PrimaryScreen.Bounds.Left; @@ -268,10 +316,24 @@ namespace SM.Base.Window break; case WindowFlags.ExclusiveFullscreen: + + + WindowState = WindowState.Fullscreen; + ApplyFullscreenResolution(); + break; default: throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null); } + + + } + + private void ApplyFullscreenResolution() + { + DisplayDevice.Default.ChangeResolution(_fullscreenResolution); + Width = _fullscreenResolution.Width; + Height = _fullscreenResolution.Height; } } } \ No newline at end of file diff --git a/SMCode/SM.Base/Window/WindowCode.cs b/SMCode/SM.Base/Window/WindowCode.cs index 0389b09..8f35b89 100644 --- a/SMCode/SM.Base/Window/WindowCode.cs +++ b/SMCode/SM.Base/Window/WindowCode.cs @@ -91,6 +91,7 @@ namespace SM.Base.Window internal static void Render(IGenericWindow window, float deltatime) { if (window.CurrentScene == null) return; + if (window.CurrentRenderPipeline == null) window.SetRenderPipeline(SMRenderer.DefaultRenderPipeline); SMRenderer.CurrentFrame++; diff --git a/SMCode/SM2D/Window/Window2DSetup.cs b/SMCode/SM2D/Window/Window2DSetup.cs index 9b340e1..d9c7ae9 100644 --- a/SMCode/SM2D/Window/Window2DSetup.cs +++ b/SMCode/SM2D/Window/Window2DSetup.cs @@ -2,6 +2,7 @@ using OpenTK.Graphics.OpenGL4; using SM.Base; using SM.Base.Window; +using SM2D.Pipelines; using SM2D.Scene; using SM2D.Shader; @@ -18,6 +19,7 @@ namespace SM2D window.ViewportCamera = new Camera(); SMRenderer.DefaultMaterialShader = ShaderCollection.Instanced; + SMRenderer.DefaultRenderPipeline = Basic2DPipeline.Pipeline; } /// diff --git a/SM_TEST/Program.cs b/SM_TEST/Program.cs index bc5c4f6..6fc29b1 100644 --- a/SM_TEST/Program.cs +++ b/SM_TEST/Program.cs @@ -1,9 +1,12 @@ -using OpenTK; +using System; +using System.Diagnostics; +using OpenTK; using OpenTK.Graphics; using OpenTK.Input; using SM.Base; using SM.Base.Window; using SM2D; +using SM2D.Drawing; using SM2D.Pipelines; using SM2D.Scene; using Font = SM.Base.Drawing.Text.Font; @@ -20,13 +23,24 @@ namespace SM_TEST { window = new GLWindow(); window.ApplySetup(new Window2DSetup()); - window.SetRenderPipeline(Basic2DPipeline.Pipeline); window.SetScene(scene = new Scene()); + scene.Objects.Add(new DrawObject2D()); + window.UpdateFrame += WindowOnUpdateFrame; window.Run(); + + Debug.WriteLine("Window Closed"); } private static void WindowOnUpdateFrame(object sender, FrameEventArgs e) { + if (SM.Base.Controls.Keyboard.IsDown(Key.F, true)) + { + window.WindowFlags = WindowFlags.ExclusiveFullscreen; + window.ChangeFullscreenResolution(DisplayDevice.Default.SelectResolution(1280,720, DisplayDevice.Default.BitsPerPixel, DisplayDevice.Default.RefreshRate)); + } + if (SM.Base.Controls.Keyboard.IsDown(Key.W, true)) window.WindowFlags = WindowFlags.Window; + if (SM.Base.Controls.Keyboard.IsDown(Key.B, true)) window.WindowFlags = WindowFlags.BorderlessWindow; + } private static void WindowOnLoad(IGenericWindow window)