diff --git a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs index dc6a847fcd..4fa099ca8b 100755 --- a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs +++ b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs @@ -102,4 +102,11 @@ namespace OpenRA.FileFormats.Graphics public readonly T Start, End; public Range( T start, T end ) { Start = start; End = end; } } + + public enum WindowMode + { + Windowed, + Fullscreen, + PseudoFullscreen, + } } diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index f0961081bd..d055bd384a 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -575,9 +575,8 @@ namespace OpenRA Renderer.SheetSize = Settings.SheetSize; - bool windowed = !Game.Settings.Fullscreen; var resolution = GetResolution(settings); - renderer = new Renderer(resolution, windowed); + renderer = new Renderer(resolution, Game.Settings.WindowMode); resolution = renderer.Resolution; controller = new Controller(); diff --git a/OpenRA.Game/GameRules/UserSettings.cs b/OpenRA.Game/GameRules/UserSettings.cs index d1a0fbef22..661658462a 100644 --- a/OpenRA.Game/GameRules/UserSettings.cs +++ b/OpenRA.Game/GameRules/UserSettings.cs @@ -18,6 +18,8 @@ */ #endregion +using OpenRA.FileFormats.Graphics; + namespace OpenRA.GameRules { public class UserSettings @@ -32,7 +34,7 @@ namespace OpenRA.GameRules // Window settings public readonly int Width = 0; public readonly int Height = 0; - public readonly bool Fullscreen = false; + public readonly WindowMode WindowMode = WindowMode.PseudoFullscreen; public bool MusicPlayer = true; // Internal game settings diff --git a/OpenRA.Game/Graphics/Renderer.cs b/OpenRA.Game/Graphics/Renderer.cs index cd6d0119ba..b86f39b205 100644 --- a/OpenRA.Game/Graphics/Renderer.cs +++ b/OpenRA.Game/Graphics/Renderer.cs @@ -51,9 +51,9 @@ namespace OpenRA.Graphics public Size Resolution { get { return device.WindowSize; } } - public Renderer(Size resolution, bool windowed) + public Renderer(Size resolution, OpenRA.FileFormats.Graphics.WindowMode windowMode) { - device = CreateDevice( Assembly.LoadFile( Path.GetFullPath( "OpenRA.Gl.dll" ) ), resolution.Width, resolution.Height, windowed, false ); + device = CreateDevice( Assembly.LoadFile( Path.GetFullPath( "OpenRA.Gl.dll" ) ), resolution.Width, resolution.Height, windowMode, false ); SpriteShader = device.CreateShader(FileSystem.Open("shaders/world-shp.fx")); LineShader = device.CreateShader(FileSystem.Open("shaders/line.fx")); @@ -69,12 +69,12 @@ namespace OpenRA.Graphics TitleFont = new SpriteFont(this, "titles.ttf", 48); } - IGraphicsDevice CreateDevice( Assembly rendererDll, int width, int height, bool windowed, bool vsync ) + IGraphicsDevice CreateDevice( Assembly rendererDll, int width, int height, WindowMode window, bool vsync ) { foreach( RendererAttribute r in rendererDll.GetCustomAttributes( typeof( RendererAttribute ), false ) ) { - return (IGraphicsDevice)r.Type.GetConstructor( new Type[] { typeof( int ), typeof( int ), typeof( bool ), typeof( bool ) } ) - .Invoke( new object[] { width, height, windowed, vsync } ); + return (IGraphicsDevice)r.Type.GetConstructor( new Type[] { typeof( int ), typeof( int ), typeof( WindowMode ), typeof( bool ) } ) + .Invoke( new object[] { width, height, window, vsync } ); } throw new NotImplementedException(); } diff --git a/OpenRA.Gl/GraphicsDevice.cs b/OpenRA.Gl/GraphicsDevice.cs index d800761934..fcf331dcd7 100644 --- a/OpenRA.Gl/GraphicsDevice.cs +++ b/OpenRA.Gl/GraphicsDevice.cs @@ -50,27 +50,31 @@ namespace OpenRA.GlRenderer throw new InvalidOperationException("GL Error"); } - public GraphicsDevice(int width, int height, bool windowed, bool vsync) + public GraphicsDevice(int width, int height, WindowMode window, bool vsync) { Sdl.SDL_Init(Sdl.SDL_INIT_NOPARACHUTE | Sdl.SDL_INIT_VIDEO); Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DOUBLEBUFFER, 1); Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_RED_SIZE, 8); Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_GREEN_SIZE, 8); Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_BLUE_SIZE, 8); - Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_ALPHA_SIZE, 0); - - if (Environment.OSVersion.Platform == PlatformID.Win32NT) - { - // pseudo-fullscreen, for sane debugging. - Environment.SetEnvironmentVariable("SDL_VIDEO_WINDOW_POS", "0,0"); - surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_NOFRAME | Sdl.SDL_OPENGL | (windowed ? 0 : Sdl.SDL_FULLSCREEN)); - } - else - { - // OSX doesn't like this, due to quirks of their WM. - surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_OPENGL | (windowed ? 0 : Sdl.SDL_FULLSCREEN)); - } - + Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_ALPHA_SIZE, 0); + + int windowFlags = 0; + switch (window) + { + case WindowMode.Fullscreen: + windowFlags |= Sdl.SDL_FULLSCREEN; + break; + case WindowMode.PseudoFullscreen: + // pseudo-fullscreen only reliably works on windows; fall back to fullscreen for everyone else + windowFlags |= (Environment.OSVersion.Platform == PlatformID.Win32NT) ? Sdl.SDL_NOFRAME : Sdl.SDL_FULLSCREEN; + break; + default: + break; + } + + surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_OPENGL | windowFlags); + Sdl.SDL_WM_SetCaption("OpenRA", "OpenRA"); Sdl.SDL_ShowCursor(0); Sdl.SDL_EnableUNICODE(1);