From 5728bf0aa50688e56ea02388d6d75b4424960317 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Mon, 16 Oct 2006 00:04:42 +0000 Subject: [PATCH] Resolution changing now works ok under windows. --- Source/Framework/Framework.cs | 9 ++-- Source/Framework/FrameworkImplementation.cs | 9 ++-- Source/Framework/WindowsImplementation.cs | 52 +++++++++++++++++++-- Source/Framework/X11Implementation.cs | 7 ++- 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/Source/Framework/Framework.cs b/Source/Framework/Framework.cs index 1fcc2188..8b7c42c5 100644 --- a/Source/Framework/Framework.cs +++ b/Source/Framework/Framework.cs @@ -113,7 +113,7 @@ namespace OpenTK.Frameworks public Framework() { - Setup(null, 640, 480, new OpenTK.OpenGL.ColorDepth(8, 8, 8, 8), 16, 0, true); + Setup(null, 640, 480, new OpenTK.OpenGL.ColorDepth(8, 8, 8, 8), 16, 0, false); } @@ -172,10 +172,9 @@ namespace OpenTK.Frameworks //this.SetStyle(ControlStyles.ResizeRedraw, true); // Redraw On Resize this.SetStyle(ControlStyles.UserPaint, true); // We'll Handle Painting Ourselves - this.Width = width; - this.Height = height; - - Fullscreen = Implementation.ToggleFullscreen(fullscreen); + this.Size = new Size(width, height); + Fullscreen = Implementation.SetResolution(fullscreen); + this.Size = new Size(width, height); // Force the window to change to the requested resolution. if (title == null) title = "OpenTK Windows application"; diff --git a/Source/Framework/FrameworkImplementation.cs b/Source/Framework/FrameworkImplementation.cs index deb88a8f..820543ac 100644 --- a/Source/Framework/FrameworkImplementation.cs +++ b/Source/Framework/FrameworkImplementation.cs @@ -15,11 +15,12 @@ namespace OpenTK.Frameworks { internal abstract class FrameworkImplementation { - abstract public void OnHandleCreated(object sender, EventArgs args); - abstract public bool IsIdle(); - abstract public void Setup(); + public abstract void OnHandleCreated(object sender, EventArgs args); + public abstract bool IsIdle(); + public abstract void Setup(); //abstract public void CloseWindow(); - abstract public bool ToggleFullscreen(bool fullscreen); + public abstract bool SetResolution(int width, int height, OpenTK.OpenGL.ColorDepth color, bool fullscreen); + public abstract bool SetResolution(bool fullscreen); } } } diff --git a/Source/Framework/WindowsImplementation.cs b/Source/Framework/WindowsImplementation.cs index f7bf3298..c81a25fa 100644 --- a/Source/Framework/WindowsImplementation.cs +++ b/Source/Framework/WindowsImplementation.cs @@ -50,7 +50,53 @@ namespace OpenTK.Frameworks { } - public override bool ToggleFullscreen(bool fullscreen) + public override bool SetResolution(int width, int height, OpenTK.OpenGL.ColorDepth color, bool fullscreen) + { + if (fullscreen) + { + Application.Idle -= framework.OnIdle; + //framework.Context.Dispose(); + + Api.DeviceMode ScreenSettings = new Api.DeviceMode(); // Device Mode + ScreenSettings.Size = (short)Marshal.SizeOf(ScreenSettings); // Size Of The Devmode Structure + ScreenSettings.PelsWidth = width; // Selected Screen Width + ScreenSettings.PelsHeight = height; // Selected Screen Height + ScreenSettings.BitsPerPel = color.Alpha + // Selected Bits Per Pixel + color.Red + + color.Green + + color.Blue; + ScreenSettings.Fields = Api.Constants.DM_BITSPERPEL | Api.Constants.DM_PELSWIDTH | Api.Constants.DM_PELSHEIGHT; + + //framework.Context = GLContext.Create(framework, framework.ColorDepth, 16, 0); + Application.Idle += framework.OnIdle; + + // Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar. + if (Api.ChangeDisplaySettings(ref ScreenSettings, Api.Constants.CDS_FULLSCREEN) == Api.Constants.DISP_CHANGE_SUCCESSFUL) + { + framework.FormBorderStyle = FormBorderStyle.None; + framework.StartPosition = FormStartPosition.Manual; + framework.Location = new System.Drawing.Point(0, 0); + //framework.Region = new Region(new Rectangle(0, 0, width, height)); + framework.Capture = true; + framework.SetTopLevel(true); + Cursor.Hide(); + + framework.Size = new Size(width, height); + + return true; + } + else + { + return false; + } + } + + framework.Size = new Size(width, height); + + return false; + } + + public override bool SetResolution(bool fullscreen) { if (fullscreen) { @@ -61,7 +107,7 @@ namespace OpenTK.Frameworks ScreenSettings.Size = (short)Marshal.SizeOf(ScreenSettings); // Size Of The Devmode Structure ScreenSettings.PelsWidth = framework.Width; // Selected Screen Width ScreenSettings.PelsHeight = framework.Height; // Selected Screen Height - ScreenSettings.BitsPerPel = framework.ColorDepth.Alpha + // Selected Bits Per Pixel + ScreenSettings.BitsPerPel = framework.ColorDepth.Alpha + // Selected Bits Per Pixel framework.ColorDepth.Red + framework.ColorDepth.Green + framework.ColorDepth.Blue; @@ -76,7 +122,7 @@ namespace OpenTK.Frameworks framework.FormBorderStyle = FormBorderStyle.None; framework.StartPosition = FormStartPosition.Manual; framework.Location = new System.Drawing.Point(0, 0); - //this.Region = new Region(new Rectangle(0, 0, width, height)); + //framework.Region = new Region(new Rectangle(0, 0, width, height)); framework.Capture = true; framework.SetTopLevel(true); Cursor.Hide(); diff --git a/Source/Framework/X11Implementation.cs b/Source/Framework/X11Implementation.cs index b2e8838c..d0ca699d 100644 --- a/Source/Framework/X11Implementation.cs +++ b/Source/Framework/X11Implementation.cs @@ -44,7 +44,12 @@ namespace OpenTK.Frameworks // } } - public override bool ToggleFullscreen(bool fullscreen) + public override bool SetResolution(int width, int height, OpenTK.OpenGL.ColorDepth color, bool fullscreen) + { + throw new Exception("The method or operation is not implemented."); + } + + public override bool SetResolution(bool fullscreen) { throw new Exception("The method or operation is not implemented."); }