diff --git a/OpenRA.Renderer.Cg/GraphicsDevice.cs b/OpenRA.Renderer.Cg/GraphicsDevice.cs
index 38d96eb8d1..b5b99b41a5 100755
--- a/OpenRA.Renderer.Cg/GraphicsDevice.cs
+++ b/OpenRA.Renderer.Cg/GraphicsDevice.cs
@@ -53,76 +53,16 @@ namespace OpenRA.Renderer.Cg
public GraphicsDevice( Size size, WindowMode window )
{
Console.WriteLine("Using Cg renderer");
- 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 );
-
- int windowFlags = 0;
- switch( window )
- {
- case WindowMode.Fullscreen:
- windowFlags |= Sdl.SDL_FULLSCREEN;
- break;
- case WindowMode.PseudoFullscreen:
- windowFlags |= Sdl.SDL_NOFRAME;
- Environment.SetEnvironmentVariable( "SDL_VIDEO_WINDOW_POS", "0,0" );
- break;
- case WindowMode.Windowed:
- Environment.SetEnvironmentVariable( "SDL_VIDEO_CENTERED", "1" );
- break;
- default:
- break;
- }
-
- var info = (Sdl.SDL_VideoInfo) Marshal.PtrToStructure(
- Sdl.SDL_GetVideoInfo(), typeof(Sdl.SDL_VideoInfo));
- Console.WriteLine("Desktop resolution: {0}x{1}",
- info.current_w, info.current_h);
-
- if (size.Width == 0 && size.Height == 0)
- {
- Console.WriteLine("No custom resolution provided, using desktop resolution");
- size = new Size( info.current_w, info.current_h );
- }
-
- Console.WriteLine("Using resolution: {0}x{1}", size.Width, size.Height);
-
- surf = Sdl.SDL_SetVideoMode( size.Width, size.Height, 0, Sdl.SDL_OPENGL | windowFlags );
- if (surf == IntPtr.Zero)
- Console.WriteLine("Failed to set video mode.");
-
- Sdl.SDL_WM_SetCaption( "OpenRA", "OpenRA" );
- Sdl.SDL_ShowCursor( 0 );
- Sdl.SDL_EnableUNICODE( 1 );
- Sdl.SDL_EnableKeyRepeat( Sdl.SDL_DEFAULT_REPEAT_DELAY, Sdl.SDL_DEFAULT_REPEAT_INTERVAL );
-
- ErrorHandler.CheckGlError();
-
- // Test for required extensions
- var required = new string[]
+ windowSize = size;
+
+ var extensions = new string[]
{
"GL_ARB_vertex_program",
"GL_ARB_fragment_program",
"GL_ARB_vertex_buffer_object",
};
-
- var extensions = Gl.glGetString(Gl.GL_EXTENSIONS);
- if (extensions == null)
- Console.WriteLine("Failed to fetch GL_EXTENSIONS, this is bad.");
-
- var missingExtensions = required.Where( r => !extensions.Contains(r) ).ToArray();
-
- if (missingExtensions.Any())
- {
- ErrorHandler.WriteGraphicsLog("Unsupported GPU: Missing extensions: {0}"
- .F(string.Join(",", missingExtensions)));
- throw new InvalidProgramException("Unsupported GPU. See graphics.log for details.");
- }
-
- windowSize = size;
+
+ surf = SdlGraphics.InitializeSdlGl(ref windowSize, window, extensions);
cgContext = Tao.Cg.Cg.cgCreateContext();
diff --git a/OpenRA.Renderer.Gl/GraphicsDevice.cs b/OpenRA.Renderer.Gl/GraphicsDevice.cs
index 4c3e9c35b0..3e592e531d 100755
--- a/OpenRA.Renderer.Gl/GraphicsDevice.cs
+++ b/OpenRA.Renderer.Gl/GraphicsDevice.cs
@@ -42,72 +42,17 @@ namespace OpenRA.Renderer.Glsl
public GraphicsDevice( Size size, WindowMode window )
{
Console.WriteLine("Using Gl renderer");
- 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 );
-
- int windowFlags = 0;
- switch( window )
- {
- case WindowMode.Fullscreen:
- windowFlags |= Sdl.SDL_FULLSCREEN;
- break;
- case WindowMode.PseudoFullscreen:
- windowFlags |= Sdl.SDL_NOFRAME;
- Environment.SetEnvironmentVariable( "SDL_VIDEO_WINDOW_POS", "0,0" );
- break;
- default:
- break;
- }
-
- var info = (Sdl.SDL_VideoInfo) Marshal.PtrToStructure(
- Sdl.SDL_GetVideoInfo(), typeof(Sdl.SDL_VideoInfo));
- Console.WriteLine("Desktop resolution: {0}x{1}",
- info.current_w, info.current_h);
-
- if (size.Width == 0 && size.Height == 0)
- {
- Console.WriteLine("No custom resolution provided, using desktop resolution");
- size = new Size( info.current_w, info.current_h );
- }
-
- Console.WriteLine("Using resolution: {0}x{1}", size.Width, size.Height);
-
- surf = Sdl.SDL_SetVideoMode( size.Width, size.Height, 0, Sdl.SDL_OPENGL | windowFlags );
-
- Sdl.SDL_WM_SetCaption( "OpenRA", "OpenRA" );
- Sdl.SDL_ShowCursor( 0 );
- Sdl.SDL_EnableUNICODE( 1 );
- Sdl.SDL_EnableKeyRepeat( Sdl.SDL_DEFAULT_REPEAT_DELAY, Sdl.SDL_DEFAULT_REPEAT_INTERVAL );
-
- ErrorHandler.CheckGlError();
+ windowSize = size;
- // Test for required extensions
- var required = new string[]
+ var extensions = new string[]
{
"GL_ARB_vertex_shader",
"GL_ARB_fragment_shader",
"GL_ARB_vertex_buffer_object",
};
-
- var extensions = Gl.glGetString(Gl.GL_EXTENSIONS);
- if (extensions == null)
- Console.WriteLine("Failed to fetch GL_EXTENSIONS, this is bad.");
-
- var missingExtensions = required.Where( r => !extensions.Contains(r) ).ToArray();
-
- if (missingExtensions.Any())
- {
- ErrorHandler.WriteGraphicsLog("Unsupported GPU: Missing extensions: {0}"
- .F(string.Join(",", missingExtensions)));
- throw new InvalidProgramException("Unsupported GPU. See graphics.log for details.");
- }
- windowSize = size;
-
+ surf = SdlGraphics.InitializeSdlGl( ref windowSize, window, extensions );
+
Gl.glEnableClientState( Gl.GL_VERTEX_ARRAY );
ErrorHandler.CheckGlError();
Gl.glEnableClientState( Gl.GL_TEXTURE_COORD_ARRAY );
diff --git a/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj b/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj
index 21bf9932a3..2d7ec8e3f6 100644
--- a/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj
+++ b/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj
@@ -1 +1 @@
-
Debug
AnyCPU
9.0.21022
2.0
{52FD9F0B-B209-4ED7-8A32-AC8033363263}
Library
OpenRA.Renderer.SdlCommon
OpenRA.Renderer.SdlCommon
v3.5
true
full
false
..\
DEBUG
prompt
4
false
none
false
..\
prompt
4
false
False
..\thirdparty\Tao\Tao.OpenGl.dll
False
..\thirdparty\Tao\Tao.Sdl.dll
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}
OpenRA.FileFormats
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}
OpenRA.Game
\ No newline at end of file
+
Debug
AnyCPU
9.0.21022
2.0
{52FD9F0B-B209-4ED7-8A32-AC8033363263}
Library
OpenRA.Renderer.SdlCommon
OpenRA.Renderer.SdlCommon
v3.5
true
full
false
..\
DEBUG
prompt
4
false
none
false
..\
prompt
4
false
False
..\thirdparty\Tao\Tao.OpenGl.dll
False
..\thirdparty\Tao\Tao.Sdl.dll
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}
OpenRA.FileFormats
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}
OpenRA.Game
\ No newline at end of file
diff --git a/OpenRA.Renderer.SdlCommon/SdlGraphics.cs b/OpenRA.Renderer.SdlCommon/SdlGraphics.cs
new file mode 100644
index 0000000000..84f9f91c47
--- /dev/null
+++ b/OpenRA.Renderer.SdlCommon/SdlGraphics.cs
@@ -0,0 +1,91 @@
+#region Copyright & License Information
+/*
+* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
+* This file is part of OpenRA, which is free software. It is made
+* available to you under the terms of the GNU General Public License
+* as published by the Free Software Foundation. For more information,
+* see COPYING.
+*/
+#endregion
+
+using System;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using Tao.OpenGl;
+using Tao.Sdl;
+using OpenRA.FileFormats.Graphics;
+
+namespace OpenRA.Renderer.SdlCommon
+{
+ public static class SdlGraphics
+ {
+ public static IntPtr InitializeSdlGl( ref Size size, WindowMode window, string[] requiredExtensions )
+ {
+ 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 );
+
+ int windowFlags = 0;
+ switch( window )
+ {
+ case WindowMode.Fullscreen:
+ windowFlags |= Sdl.SDL_FULLSCREEN;
+ break;
+ case WindowMode.PseudoFullscreen:
+ windowFlags |= Sdl.SDL_NOFRAME;
+ Environment.SetEnvironmentVariable( "SDL_VIDEO_WINDOW_POS", "0,0" );
+ break;
+ case WindowMode.Windowed:
+ Environment.SetEnvironmentVariable( "SDL_VIDEO_CENTERED", "1" );
+ break;
+ default:
+ break;
+ }
+
+ var info = (Sdl.SDL_VideoInfo) Marshal.PtrToStructure(
+ Sdl.SDL_GetVideoInfo(), typeof(Sdl.SDL_VideoInfo));
+ Console.WriteLine("Desktop resolution: {0}x{1}",
+ info.current_w, info.current_h);
+
+ if (size.Width == 0 && size.Height == 0)
+ {
+ Console.WriteLine("No custom resolution provided, using desktop resolution");
+ size = new Size( info.current_w, info.current_h );
+ }
+
+ Console.WriteLine("Using resolution: {0}x{1}", size.Width, size.Height);
+
+ var surf = Sdl.SDL_SetVideoMode( size.Width, size.Height, 0, Sdl.SDL_OPENGL | windowFlags );
+ if (surf == IntPtr.Zero)
+ Console.WriteLine("Failed to set video mode.");
+
+ Sdl.SDL_WM_SetCaption( "OpenRA", "OpenRA" );
+ Sdl.SDL_ShowCursor( 0 );
+ Sdl.SDL_EnableUNICODE( 1 );
+ Sdl.SDL_EnableKeyRepeat( Sdl.SDL_DEFAULT_REPEAT_DELAY, Sdl.SDL_DEFAULT_REPEAT_INTERVAL );
+
+ ErrorHandler.CheckGlError();
+
+ var extensions = Gl.glGetString(Gl.GL_EXTENSIONS);
+ if (extensions == null)
+ Console.WriteLine("Failed to fetch GL_EXTENSIONS, this is bad.");
+
+ var missingExtensions = requiredExtensions.Where( r => !extensions.Contains(r) ).ToArray();
+
+ if (missingExtensions.Any())
+ {
+ ErrorHandler.WriteGraphicsLog("Unsupported GPU: Missing extensions: {0}"
+ .F(string.Join(",", missingExtensions)));
+ throw new InvalidProgramException("Unsupported GPU. See graphics.log for details.");
+ }
+
+ return surf;
+ }
+ }
+}
+