From 761ab4ab78cae79715a17c1cd0958735556ac2fb Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@zdoom.fake>
Date: Sun, 18 Aug 2013 14:16:33 +0200
Subject: [PATCH] - moved all system specific code out of gl_interface.cpp into
 the respective Video classes (Win32GLVideo andSDLGLVideo.) (SDL side not
 tested yet!)

---
 gzdoom.vcproj                    | 782 ++++++++++++++++---------------
 src/gl/system/gl_framebuffer.cpp |   4 +-
 src/gl/system/gl_interface.cpp   | 558 +---------------------
 src/gl/system/gl_interface.h     |  12 -
 src/gl/system/gl_system.h        |   2 +
 src/sdl/sdlglvideo.cpp           |  71 ++-
 src/sdl/sdlglvideo.h             |   4 +
 src/win32/hardware.cpp           |   7 +-
 src/win32/win32gliface.cpp       | 452 +++++++++++++++++-
 src/win32/win32gliface.h         |  32 +-
 10 files changed, 961 insertions(+), 963 deletions(-)

diff --git a/gzdoom.vcproj b/gzdoom.vcproj
index e24992960d..b7e52df620 100644
--- a/gzdoom.vcproj
+++ b/gzdoom.vcproj
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="8.00"
+	Version="8,00"
 	Name="zdoom"
 	ProjectGUID="{8049475B-5C87-46F9-9358-635218A4EF18}"
 	RootNamespace=" zdoom"
@@ -140,6 +140,112 @@
 				Name="VCPostBuildEventTool"
 			/>
 		</Configuration>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory=".\Debug"
+			IntermediateDirectory=".\Debug"
+			ConfigurationType="1"
+			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="false"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+				Description="Checking gitinfo.h..."
+				CommandLine="&quot;$(OutDir)\updaterevision.exe&quot; src/gitinfo.h"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				PreprocessorDefinitions="_DEBUG"
+				MkTypLibCompatible="true"
+				SuppressStartupBanner="true"
+				TargetEnvironment="1"
+				TypeLibraryName=".\Debug/zdoom.tlb"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="src\win32;src\sound;src;zlib;src\g_shared;src\g_doom;src\g_raven;src\g_heretic;src\g_hexen;src\g_strife;&quot;jpeg-6b&quot;;&quot;game-music-emu\gme&quot;;gdtoa;bzip2;lzma\C"
+				PreprocessorDefinitions="WIN32,_DEBUG,_WIN32,_WINDOWS,_CRTDBG_MAP_ALLOC,HAVE_STRUPR,HAVE_FILELENGTH;NO_VA_COPY,BACKPATCH,HAVE_FLUIDSYNTH,DYN_FLUIDSYNTH"
+				MinimalRebuild="true"
+				RuntimeLibrary="1"
+				EnableFunctionLevelLinking="true"
+				ForceConformanceInForLoopScope="true"
+				PrecompiledHeaderFile=""
+				AssemblerListingLocation=".\Debug/"
+				ObjectFile=".\Debug/"
+				ProgramDataBaseFileName=".\Debug/"
+				WarningLevel="3"
+				SuppressStartupBanner="true"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="4"
+				CompileAs="0"
+				DisableSpecificWarnings="4996"
+				ForcedIncludeFiles=""
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="_DEBUG"
+				Culture="1033"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalOptions="/MACHINE:I386"
+				AdditionalDependencies="gdi32.lib user32.lib comctl32.lib shell32.lib advapi32.lib comdlg32.lib ole32.lib dxguid.lib dsound.lib dinput8.lib strmiids.lib wsock32.lib winmm.lib setupapi.lib ws2_32.lib oleaut32.lib fmodex_vc.lib opengl32.lib glu32.lib"
+				OutputFile="../gzdoomd.exe"
+				LinkIncremental="2"
+				SuppressStartupBanner="true"
+				AdditionalLibraryDirectories=""
+				IgnoreDefaultLibraryNames="libcmt;msvcrtd;msvcrt"
+				DelayLoadDLLs="fmodex.dll"
+				GenerateDebugInformation="true"
+				ProgramDatabaseFile=".\Debug/zdoomd.pdb"
+				SubSystem="2"
+				StackReserveSize="0"
+				TerminalServerAware="2"
+				SetChecksum="false"
+				TargetMachine="0"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
 		<Configuration
 			Name="Release|x64"
 			OutputDirectory="$(PlatformName)\$(ConfigurationName)"
@@ -254,112 +360,6 @@
 				Name="VCPostBuildEventTool"
 			/>
 		</Configuration>
-		<Configuration
-			Name="Debug|Win32"
-			OutputDirectory=".\Debug"
-			IntermediateDirectory=".\Debug"
-			ConfigurationType="1"
-			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
-			UseOfMFC="0"
-			ATLMinimizesCRunTimeLibraryUsage="false"
-			>
-			<Tool
-				Name="VCPreBuildEventTool"
-				Description="Checking gitinfo.h..."
-				CommandLine="&quot;$(OutDir)\updaterevision.exe&quot; src/gitinfo.h"
-			/>
-			<Tool
-				Name="VCCustomBuildTool"
-			/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"
-			/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"
-			/>
-			<Tool
-				Name="VCMIDLTool"
-				PreprocessorDefinitions="_DEBUG"
-				MkTypLibCompatible="true"
-				SuppressStartupBanner="true"
-				TargetEnvironment="1"
-				TypeLibraryName=".\Debug/zdoom.tlb"
-			/>
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				AdditionalIncludeDirectories="src\win32;src\sound;src;zlib;src\g_shared;src\g_doom;src\g_raven;src\g_heretic;src\g_hexen;src\g_strife;&quot;jpeg-6b&quot;;&quot;game-music-emu\gme&quot;;gdtoa;bzip2;lzma\C"
-				PreprocessorDefinitions="WIN32,_DEBUG,_WIN32,_WINDOWS,_CRTDBG_MAP_ALLOC,HAVE_STRUPR,HAVE_FILELENGTH;NO_VA_COPY,BACKPATCH,HAVE_FLUIDSYNTH,DYN_FLUIDSYNTH"
-				MinimalRebuild="true"
-				RuntimeLibrary="1"
-				EnableFunctionLevelLinking="true"
-				ForceConformanceInForLoopScope="true"
-				PrecompiledHeaderFile=""
-				AssemblerListingLocation=".\Debug/"
-				ObjectFile=".\Debug/"
-				ProgramDataBaseFileName=".\Debug/"
-				WarningLevel="3"
-				SuppressStartupBanner="true"
-				Detect64BitPortabilityProblems="true"
-				DebugInformationFormat="4"
-				CompileAs="0"
-				DisableSpecificWarnings="4996"
-				ForcedIncludeFiles=""
-			/>
-			<Tool
-				Name="VCManagedResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCResourceCompilerTool"
-				PreprocessorDefinitions="_DEBUG"
-				Culture="1033"
-			/>
-			<Tool
-				Name="VCPreLinkEventTool"
-			/>
-			<Tool
-				Name="VCLinkerTool"
-				AdditionalOptions="/MACHINE:I386"
-				AdditionalDependencies="gdi32.lib user32.lib comctl32.lib shell32.lib advapi32.lib comdlg32.lib ole32.lib dxguid.lib dsound.lib dinput8.lib strmiids.lib wsock32.lib winmm.lib setupapi.lib ws2_32.lib oleaut32.lib fmodex_vc.lib opengl32.lib glu32.lib"
-				OutputFile="../gzdoomd.exe"
-				LinkIncremental="2"
-				SuppressStartupBanner="true"
-				AdditionalLibraryDirectories=""
-				IgnoreDefaultLibraryNames="libcmt;msvcrtd;msvcrt"
-				DelayLoadDLLs="fmodex.dll"
-				GenerateDebugInformation="true"
-				ProgramDatabaseFile=".\Debug/zdoomd.pdb"
-				SubSystem="2"
-				StackReserveSize="0"
-				TerminalServerAware="2"
-				SetChecksum="false"
-				TargetMachine="0"
-			/>
-			<Tool
-				Name="VCALinkTool"
-			/>
-			<Tool
-				Name="VCManifestTool"
-			/>
-			<Tool
-				Name="VCXDCMakeTool"
-			/>
-			<Tool
-				Name="VCBscMakeTool"
-			/>
-			<Tool
-				Name="VCFxCopTool"
-			/>
-			<Tool
-				Name="VCAppVerifierTool"
-			/>
-			<Tool
-				Name="VCWebDeploymentTool"
-			/>
-			<Tool
-				Name="VCPostBuildEventTool"
-			/>
-		</Configuration>
 		<Configuration
 			Name="Debug|x64"
 			OutputDirectory="$(PlatformName)\$(ConfigurationName)"
@@ -973,7 +973,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					>
 					<Tool
 						Name="VCCustomBuildTool"
@@ -983,7 +983,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					>
 					<Tool
 						Name="VCCustomBuildTool"
@@ -1605,6 +1605,16 @@
 							Outputs="$(IntDir)\$(InputName).obj"
 						/>
 					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+							Description="Assembling $(InputPath)..."
+							CommandLine="nasm -g -o &quot;$(IntDir)\$(InputName).obj&quot; -f win32 &quot;$(InputPath)&quot; -isrc/&#x0D;&#x0A;$(OutDir)\fixrtext &quot;$(IntDir)\$(InputName).obj&quot;&#x0D;&#x0A;"
+							Outputs="$(IntDir)\$(InputName).obj"
+						/>
+					</FileConfiguration>
 					<FileConfiguration
 						Name="Release|x64"
 						ExcludedFromBuild="true"
@@ -1616,16 +1626,6 @@
 							Outputs="$(IntDir)/$(InputName).obj"
 						/>
 					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-							Description="Assembling $(InputPath)..."
-							CommandLine="nasm -g -o &quot;$(IntDir)\$(InputName).obj&quot; -f win32 &quot;$(InputPath)&quot; -isrc/&#x0D;&#x0A;$(OutDir)\fixrtext &quot;$(IntDir)\$(InputName).obj&quot;&#x0D;&#x0A;"
-							Outputs="$(IntDir)\$(InputName).obj"
-						/>
-					</FileConfiguration>
 					<FileConfiguration
 						Name="Debug|x64"
 						ExcludedFromBuild="true"
@@ -1651,6 +1651,16 @@
 							Outputs="$(IntDir)\$(InputName).obj"
 						/>
 					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+							Description="Assembling $(InputPath)..."
+							CommandLine="nasm -g -o &quot;$(IntDir)\$(InputName).obj&quot; -f win32 &quot;$(InputPath)&quot; -isrc/&#x0D;&#x0A;$(OutDir)\fixrtext &quot;$(IntDir)\$(InputName).obj&quot;&#x0D;&#x0A;"
+							Outputs="$(IntDir)\$(InputName).obj"
+						/>
+					</FileConfiguration>
 					<FileConfiguration
 						Name="Release|x64"
 						ExcludedFromBuild="true"
@@ -1662,16 +1672,6 @@
 							Outputs="$(IntDir)/$(InputName).obj"
 						/>
 					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-							Description="Assembling $(InputPath)..."
-							CommandLine="nasm -g -o &quot;$(IntDir)\$(InputName).obj&quot; -f win32 &quot;$(InputPath)&quot; -isrc/&#x0D;&#x0A;$(OutDir)\fixrtext &quot;$(IntDir)\$(InputName).obj&quot;&#x0D;&#x0A;"
-							Outputs="$(IntDir)\$(InputName).obj"
-						/>
-					</FileConfiguration>
 					<FileConfiguration
 						Name="Debug|x64"
 						ExcludedFromBuild="true"
@@ -1697,6 +1697,16 @@
 							Outputs="$(IntDir)\$(InputName).obj"
 						/>
 					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+							Description="Assembling $(InputPath)..."
+							CommandLine="nasm -g -o &quot;$(IntDir)\$(InputName).obj&quot; -f win32 &quot;$(InputPath)&quot; -isrc/&#x0D;&#x0A;$(OutDir)\fixrtext &quot;$(IntDir)\$(InputName).obj&quot;&#x0D;&#x0A;"
+							Outputs="$(IntDir)\$(InputName).obj"
+						/>
+					</FileConfiguration>
 					<FileConfiguration
 						Name="Release|x64"
 						ExcludedFromBuild="true"
@@ -1708,16 +1718,6 @@
 							Outputs="$(IntDir)/$(InputName).obj"
 						/>
 					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-							Description="Assembling $(InputPath)..."
-							CommandLine="nasm -g -o &quot;$(IntDir)\$(InputName).obj&quot; -f win32 &quot;$(InputPath)&quot; -isrc/&#x0D;&#x0A;$(OutDir)\fixrtext &quot;$(IntDir)\$(InputName).obj&quot;&#x0D;&#x0A;"
-							Outputs="$(IntDir)\$(InputName).obj"
-						/>
-					</FileConfiguration>
 					<FileConfiguration
 						Name="Debug|x64"
 						ExcludedFromBuild="true"
@@ -1743,6 +1743,16 @@
 							Outputs="$(IntDir)\$(InputName).obj"
 						/>
 					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+							Description="Assembling $(InputPath)..."
+							CommandLine="nasm -g -o &quot;$(IntDir)\$(InputName).obj&quot; -f win32 &quot;$(InputPath)&quot; -isrc/&#x0D;&#x0A;$(OutDir)\fixrtext &quot;$(IntDir)\$(InputName).obj&quot;&#x0D;&#x0A;"
+							Outputs="$(IntDir)\$(InputName).obj"
+						/>
+					</FileConfiguration>
 					<FileConfiguration
 						Name="Release|x64"
 						ExcludedFromBuild="true"
@@ -1754,16 +1764,6 @@
 							Outputs="$(IntDir)/$(InputName).obj"
 						/>
 					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-							Description="Assembling $(InputPath)..."
-							CommandLine="nasm -g -o &quot;$(IntDir)\$(InputName).obj&quot; -f win32 &quot;$(InputPath)&quot; -isrc/&#x0D;&#x0A;$(OutDir)\fixrtext &quot;$(IntDir)\$(InputName).obj&quot;&#x0D;&#x0A;"
-							Outputs="$(IntDir)\$(InputName).obj"
-						/>
-					</FileConfiguration>
 					<FileConfiguration
 						Name="Debug|x64"
 						ExcludedFromBuild="true"
@@ -1789,6 +1789,16 @@
 							Outputs="$(IntDir)\$(InputName).obj"
 						/>
 					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+							Description="Assembling $(InputPath)..."
+							CommandLine="nasm -g -o &quot;$(IntDir)\$(InputName).obj&quot; -f win32 &quot;$(InputPath)&quot; -isrc/&#x0D;&#x0A;$(OutDir)\fixrtext &quot;$(IntDir)\$(InputName).obj&quot;&#x0D;&#x0A;"
+							Outputs="$(IntDir)\$(InputName).obj"
+						/>
+					</FileConfiguration>
 					<FileConfiguration
 						Name="Release|x64"
 						ExcludedFromBuild="true"
@@ -1800,16 +1810,6 @@
 							Outputs="$(IntDir)/$(InputName).obj"
 						/>
 					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-							Description="Assembling $(InputPath)..."
-							CommandLine="nasm -g -o &quot;$(IntDir)\$(InputName).obj&quot; -f win32 &quot;$(InputPath)&quot; -isrc/&#x0D;&#x0A;$(OutDir)\fixrtext &quot;$(IntDir)\$(InputName).obj&quot;&#x0D;&#x0A;"
-							Outputs="$(IntDir)\$(InputName).obj"
-						/>
-					</FileConfiguration>
 					<FileConfiguration
 						Name="Debug|x64"
 						ExcludedFromBuild="true"
@@ -1837,6 +1837,14 @@
 							Name="VCCustomBuildTool"
 						/>
 					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+						/>
+					</FileConfiguration>
 					<FileConfiguration
 						Name="Release|x64"
 						>
@@ -1847,14 +1855,6 @@
 							Outputs="$(IntDir)/$(InputName).obj"
 						/>
 					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-						/>
-					</FileConfiguration>
 					<FileConfiguration
 						Name="Debug|x64"
 						>
@@ -2231,7 +2231,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2239,7 +2239,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2443,14 +2443,6 @@
 						AdditionalIncludeDirectories="src\win32;$(NoInherit)"
 					/>
 				</FileConfiguration>
-				<FileConfiguration
-					Name="Release|x64"
-					>
-					<Tool
-						Name="VCResourceCompilerTool"
-						AdditionalIncludeDirectories="src\win32;$(NoInherit)"
-					/>
-				</FileConfiguration>
 				<FileConfiguration
 					Name="Debug|Win32"
 					>
@@ -2460,6 +2452,14 @@
 						AdditionalIncludeDirectories="src\win32;$(NoInherit)"
 					/>
 				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|x64"
+					>
+					<Tool
+						Name="VCResourceCompilerTool"
+						AdditionalIncludeDirectories="src\win32;$(NoInherit)"
+					/>
+				</FileConfiguration>
 				<FileConfiguration
 					Name="Debug|x64"
 					>
@@ -2774,7 +2774,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2782,7 +2782,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2814,7 +2814,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2822,7 +2822,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2851,7 +2851,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2860,7 +2860,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2890,7 +2890,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2898,7 +2898,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2927,7 +2927,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2936,7 +2936,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2967,7 +2967,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -2976,7 +2976,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3006,7 +3006,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3014,7 +3014,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3043,7 +3043,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3052,7 +3052,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3083,7 +3083,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3092,7 +3092,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3123,7 +3123,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3132,7 +3132,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3162,7 +3162,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3170,7 +3170,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3197,14 +3197,6 @@
 						Name="VCCustomBuildTool"
 					/>
 				</FileConfiguration>
-				<FileConfiguration
-					Name="Release|x64"
-					ExcludedFromBuild="true"
-					>
-					<Tool
-						Name="VCCustomBuildTool"
-					/>
-				</FileConfiguration>
 				<FileConfiguration
 					Name="Debug|Win32"
 					ExcludedFromBuild="true"
@@ -3213,6 +3205,14 @@
 						Name="VCCustomBuildTool"
 					/>
 				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|x64"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+					/>
+				</FileConfiguration>
 				<FileConfiguration
 					Name="Debug|x64"
 					ExcludedFromBuild="true"
@@ -3222,6 +3222,46 @@
 					/>
 				</FileConfiguration>
 			</File>
+			<File
+				RelativePath=".\src\sdl\sdlglvideo.cpp"
+				>
+				<FileConfiguration
+					Name="Release|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath=".\src\sdl\sdlglvideo.h"
+				>
+				<FileConfiguration
+					Name="Release|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+					/>
+				</FileConfiguration>
+			</File>
 			<File
 				RelativePath=".\src\sdl\sdlvideo.cpp"
 				>
@@ -3234,7 +3274,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3242,7 +3282,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3270,7 +3310,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3278,7 +3318,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3308,7 +3348,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3318,7 +3358,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3362,7 +3402,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3370,7 +3410,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					ExcludedFromBuild="true"
 					>
 					<Tool
@@ -3404,7 +3444,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release|x64"
+					Name="Debug|Win32"
 					>
 					<Tool
 						Name="VCCustomBuildTool"
@@ -3414,7 +3454,7 @@
 					/>
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Debug|Win32"
+					Name="Release|x64"
 					>
 					<Tool
 						Name="VCCustomBuildTool"
@@ -4249,7 +4289,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4257,7 +4297,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4285,7 +4325,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4293,7 +4333,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4321,7 +4361,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4329,7 +4369,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4357,7 +4397,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4365,7 +4405,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4393,7 +4433,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4401,7 +4441,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4429,7 +4469,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4437,7 +4477,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4465,7 +4505,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4473,7 +4513,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4505,7 +4545,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4513,7 +4553,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4545,7 +4585,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4553,7 +4593,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4581,7 +4621,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4589,7 +4629,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4617,7 +4657,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4625,7 +4665,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4653,7 +4693,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4661,7 +4701,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4689,7 +4729,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4697,7 +4737,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4725,7 +4765,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4733,7 +4773,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4761,7 +4801,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4769,7 +4809,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4797,7 +4837,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4805,7 +4845,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4833,7 +4873,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4841,7 +4881,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4873,7 +4913,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4881,7 +4921,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4909,7 +4949,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4917,7 +4957,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4945,7 +4985,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4953,7 +4993,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4981,7 +5021,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -4989,7 +5029,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5021,7 +5061,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5029,7 +5069,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5057,7 +5097,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5065,7 +5105,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5093,7 +5133,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5101,7 +5141,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5129,7 +5169,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5137,7 +5177,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5169,7 +5209,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5177,7 +5217,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5205,7 +5245,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5213,7 +5253,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5241,7 +5281,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5249,7 +5289,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5277,7 +5317,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5285,7 +5325,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5313,7 +5353,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5321,7 +5361,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5349,7 +5389,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5357,7 +5397,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5385,7 +5425,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5393,7 +5433,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5421,7 +5461,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5429,7 +5469,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5457,7 +5497,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5465,7 +5505,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5493,7 +5533,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5501,7 +5541,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5529,7 +5569,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5537,7 +5577,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5565,7 +5605,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5573,7 +5613,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5601,7 +5641,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5609,7 +5649,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5637,7 +5677,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5645,7 +5685,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5673,7 +5713,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5681,7 +5721,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5709,7 +5749,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5717,7 +5757,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5745,7 +5785,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5753,7 +5793,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5781,7 +5821,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5789,7 +5829,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5817,7 +5857,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5825,7 +5865,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5861,7 +5901,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5869,7 +5909,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5897,7 +5937,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5905,7 +5945,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5933,7 +5973,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5941,7 +5981,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5969,7 +6009,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -5977,7 +6017,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6005,7 +6045,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6013,7 +6053,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6041,7 +6081,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6049,7 +6089,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6077,7 +6117,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6085,7 +6125,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6113,7 +6153,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6121,7 +6161,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6149,7 +6189,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6157,7 +6197,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6185,7 +6225,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6193,7 +6233,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6221,7 +6261,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6229,7 +6269,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6257,7 +6297,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6265,7 +6305,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6313,7 +6353,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6321,7 +6361,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6349,7 +6389,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6357,7 +6397,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6385,7 +6425,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6393,7 +6433,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6421,7 +6461,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6429,7 +6469,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6457,7 +6497,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6465,7 +6505,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6493,7 +6533,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6501,7 +6541,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6529,7 +6569,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6537,7 +6577,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6565,7 +6605,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6573,7 +6613,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6601,7 +6641,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6609,7 +6649,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6637,7 +6677,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6645,7 +6685,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6673,7 +6713,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6681,7 +6721,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6709,7 +6749,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6717,7 +6757,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6745,7 +6785,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6753,7 +6793,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6781,7 +6821,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6789,7 +6829,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6821,7 +6861,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6829,7 +6869,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6860,14 +6900,6 @@
 							Name="VCCLCompilerTool"
 						/>
 					</FileConfiguration>
-					<FileConfiguration
-						Name="Release|x64"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
 					<FileConfiguration
 						Name="Debug|Win32"
 						ExcludedFromBuild="true"
@@ -6877,6 +6909,14 @@
 							GeneratePreprocessedFile="0"
 						/>
 					</FileConfiguration>
+					<FileConfiguration
+						Name="Release|x64"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
 					<FileConfiguration
 						Name="Debug|x64"
 						ExcludedFromBuild="true"
@@ -6899,7 +6939,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6907,7 +6947,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6935,7 +6975,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Release|x64"
+						Name="Debug|Win32"
 						ExcludedFromBuild="true"
 						>
 						<Tool
@@ -6943,7 +6983,7 @@
 						/>
 					</FileConfiguration>
 					<FileConfiguration
-						Name="Debug|Win32"
+						Name="Release|x64"
 						ExcludedFromBuild="true"
 						>
 						<Tool
diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp
index 0409151a90..6ba5032bb8 100644
--- a/src/gl/system/gl_framebuffer.cpp
+++ b/src/gl/system/gl_framebuffer.cpp
@@ -96,7 +96,7 @@ OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, int width, int height, int
 	needsetgamma = true;
 	swapped = false;
 	Accel2D = true;
-	if (gl.SetVSync!=NULL) gl.SetVSync(vid_vsync);
+	SetVSync(vid_vsync);
 }
 
 OpenGLFrameBuffer::~OpenGLFrameBuffer()
@@ -228,7 +228,7 @@ void OpenGLFrameBuffer::Swap()
 		//DoSetGamma();
 		needsetgamma = false;
 	}
-	gl.SwapBuffers();
+	SwapBuffers();
 	Finish.Unclock();
 	swapped = true;
 	FHardwareTexture::UnbindAll();
diff --git a/src/gl/system/gl_interface.cpp b/src/gl/system/gl_interface.cpp
index 41e09ebd5c..1576b5c490 100644
--- a/src/gl/system/gl_interface.cpp
+++ b/src/gl/system/gl_interface.cpp
@@ -5,7 +5,7 @@
 **
 **---------------------------------------------------------------------------
 ** Copyright 2005 Tim Stump
-** Copyright 2005 Christoph Oelckers
+** Copyright 2005-2013 Christoph Oelckers
 ** All rights reserved.
 **
 ** Redistribution and use in source and binary forms, with or without
@@ -51,19 +51,8 @@
 static void APIENTRY glBlendEquationDummy (GLenum mode);
 
 
-#if !defined (unix) && !defined (__APPLE__)
-PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; // = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
-PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
-#endif
-
 static TArray<FString>  m_Extensions;
 
-#if !defined (unix) && !defined (__APPLE__)
-HWND m_Window;
-HDC m_hDC;
-HGLRC m_hRC;
-#endif
-
 #define gl pgl
 
 RenderContext * gl;
@@ -71,143 +60,6 @@ RenderContext * gl;
 int occlusion_type=0;
 
 
-//==========================================================================
-//
-// 
-//
-//==========================================================================
-
-#if !defined (unix) && !defined (__APPLE__)
-static HWND InitDummy()
-{
-	HMODULE g_hInst = GetModuleHandle(NULL);
-	HWND dummy;
-	//Create a rect structure for the size/position of the window
-	RECT windowRect;
-	windowRect.left = 0;
-	windowRect.right = 64;
-	windowRect.top = 0;
-	windowRect.bottom = 64;
-
-	//Window class structure
-	WNDCLASS wc;
-
-	//Fill in window class struct
-	wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
-	wc.lpfnWndProc = (WNDPROC) DefWindowProc;
-	wc.cbClsExtra = 0;
-	wc.cbWndExtra = 0;
-	wc.hInstance = g_hInst;
-	wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
-	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
-	wc.hbrBackground = NULL;
-	wc.lpszMenuName = NULL;
-	wc.lpszClassName = "GZDoomOpenGLDummyWindow";
-
-	//Register window class
-	if(!RegisterClass(&wc))
-	{
-		return 0;
-	}
-
-	//Set window style & extended style
-	DWORD style, exStyle;
-	exStyle = WS_EX_CLIENTEDGE;
-	style = WS_SYSMENU | WS_BORDER | WS_CAPTION;// | WS_VISIBLE;
-
-	//Adjust the window size so that client area is the size requested
-	AdjustWindowRectEx(&windowRect, style, false, exStyle);
-
-	//Create Window
-	if(!(dummy = CreateWindowEx(exStyle,
-		"GZDoomOpenGLDummyWindow",
-		"GZDOOM",
-		WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style,
-		0, 0,
-		windowRect.right-windowRect.left,
-		windowRect.bottom-windowRect.top,
-		NULL, NULL,
-		g_hInst,
-		NULL)))
-	{
-		UnregisterClass("GZDoomOpenGLDummyWindow", g_hInst);
-		return 0;
-	}
-	ShowWindow(dummy, SW_HIDE);
-
-	return dummy;
-}
-
-//==========================================================================
-//
-// 
-//
-//==========================================================================
-
-static void ShutdownDummy(HWND dummy)
-{
-	DestroyWindow(dummy);
-	UnregisterClass("GZDoomOpenGLDummyWindow", GetModuleHandle(NULL));
-}
-
-
-//==========================================================================
-//
-// 
-//
-//==========================================================================
-
-static bool ReadInitExtensions()
-{
-	HDC hDC;
-	HGLRC hRC;
-	HWND dummy;
-
-	PIXELFORMATDESCRIPTOR pfd = {
-		sizeof(PIXELFORMATDESCRIPTOR),
-			1,
-			PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
-			PFD_TYPE_RGBA,
-			32, // color depth
-			0, 0, 0, 0, 0, 0,
-			0,
-			0,
-			0,
-			0, 0, 0, 0,
-			16, // z depth
-			0, // stencil buffer
-			0,
-			PFD_MAIN_PLANE,
-			0,
-			0, 0, 0
-	};
-
-	int pixelFormat;
-
-	// we have to create a dummy window to init stuff from or the full init stuff fails
-	dummy = InitDummy();
-
-	hDC = GetDC(dummy);
-	pixelFormat = ChoosePixelFormat(hDC, &pfd);
-	DescribePixelFormat(hDC, pixelFormat, sizeof(pfd), &pfd);
-
-	SetPixelFormat(hDC, pixelFormat, &pfd);
-
-	hRC = wglCreateContext(hDC);
-	wglMakeCurrent(hDC, hRC);
-
-	wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
-	wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
-	// any extra stuff here?
-
-	wglMakeCurrent(NULL, NULL);
-	wglDeleteContext(hRC);
-	ReleaseDC(dummy, hDC);
-	ShutdownDummy(dummy);
-
-	return true;
-}
-#endif
 
 //==========================================================================
 //
@@ -296,12 +148,6 @@ static void APIENTRY LoadExtensions()
 	if (strcmp(version, "2.1") >= 0) gl->flags|=RFL_GL_21;
 	if (strcmp(version, "3.0") >= 0) gl->flags|=RFL_GL_30;
 
-
-#if !defined (unix) && !defined (__APPLE__)
-	PFNWGLSWAPINTERVALEXTPROC vs = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
-	if (vs) gl->SetVSync = vs;
-#endif
-
 	glGetIntegerv(GL_MAX_TEXTURE_SIZE,&gl->max_texturesize);
 	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 	
@@ -437,21 +283,6 @@ static void APIENTRY LoadExtensions()
 
 		gl->flags|=RFL_FRAMEBUFFER;
 	}
-#if 0
-	else if (CheckExtension("GL_EXT_framebuffer_object") && 
-			 CheckExtension("GL_EXT_packed_depth_stencil"))
-	{
-		gl->GenFramebuffers			= (PFNGLGENFRAMEBUFFERSPROC)wglGetProcAddress("glGenFramebuffersEXT");
-		gl->BindFramebuffer			= (PFNGLBINDFRAMEBUFFERPROC)wglGetProcAddress("glBindFramebufferEXT");
-		gl->FramebufferTexture2D	= (PFNGLFRAMEBUFFERTEXTURE2DPROC)wglGetProcAddress("glFramebufferTexture2DEXT");
-		gl->GenRenderbuffers		= (PFNGLGENRENDERBUFFERSPROC)wglGetProcAddress("glGenRenderbuffersEXT");
-		gl->BindRenderbuffer		= (PFNGLBINDRENDERBUFFERPROC)wglGetProcAddress("glBindRenderbufferEXT");
-		gl->RenderbufferStorage		= (PFNGLRENDERBUFFERSTORAGEPROC)wglGetProcAddress("glRenderbufferStorageEXT");
-		gl->FramebufferRenderbuffer	= (PFNGLFRAMEBUFFERRENDERBUFFERPROC)wglGetProcAddress("glFramebufferRenderbufferEXT");
-
-		gl->flags|=RFL_FRAMEBUFFER;
-	}
-#endif
 
 #if 0
 	if (CheckExtension("GL_ARB_texture_buffer_object") && 
@@ -509,372 +340,6 @@ static void APIENTRY PrintStartupLog()
 //
 //==========================================================================
 
-#if !defined (unix) && !defined (__APPLE__)
-static bool SetupPixelFormat(HDC hDC, bool allowsoftware, bool nostencil, int multisample)
-{
-	int colorDepth;
-	HDC deskDC;
-	int attributes[26];
-	int pixelFormat;
-	unsigned int numFormats;
-	float attribsFloat[] = {0.0f, 0.0f};
-	int stencil;
-	
-	deskDC = GetDC(GetDesktopWindow());
-	colorDepth = GetDeviceCaps(deskDC, BITSPIXEL);
-	ReleaseDC(GetDesktopWindow(), deskDC);
-
-	/*
-	if (!nostencil && colorDepth < 32)
-	{
-		Printf("R_OPENGL: Desktop not in 32 bit mode!\n");
-		return false;
-	}
-	*/
-
-	if (!nostencil)
-	{
-		for (stencil=1;stencil>=0;stencil--)
-		{
-			if (wglChoosePixelFormatARB && stencil)
-			{
-				attributes[0]	=	WGL_RED_BITS_ARB; //bits
-				attributes[1]	=	8;
-				attributes[2]	=	WGL_GREEN_BITS_ARB; //bits
-				attributes[3]	=	8;
-				attributes[4]	=	WGL_BLUE_BITS_ARB; //bits
-				attributes[5]	=	8;
-				attributes[6]	=	WGL_ALPHA_BITS_ARB;
-				attributes[7]	=	8;
-				attributes[8]	=	WGL_DEPTH_BITS_ARB;
-				attributes[9]	=	24;
-				attributes[10]	=	WGL_STENCIL_BITS_ARB;
-				attributes[11]	=	8;
-			
-				attributes[12]	=	WGL_DRAW_TO_WINDOW_ARB;	//required to be true
-				attributes[13]	=	true;
-				attributes[14]	=	WGL_SUPPORT_OPENGL_ARB;
-				attributes[15]	=	true;
-				attributes[16]	=	WGL_DOUBLE_BUFFER_ARB;
-				attributes[17]	=	true;
-			
-				attributes[18]	=	WGL_ACCELERATION_ARB;	//required to be FULL_ACCELERATION_ARB
-				if (allowsoftware)
-				{
-					attributes[19]	=	WGL_NO_ACCELERATION_ARB;
-				}
-				else
-				{
-					attributes[19]	=	WGL_FULL_ACCELERATION_ARB;
-				}
-			
-				if (multisample > 0)
-				{
-					attributes[20]	=	WGL_SAMPLE_BUFFERS_ARB;
-					attributes[21]	=	true;
-					attributes[22]	=	WGL_SAMPLES_ARB;
-					attributes[23]	=	multisample;
-				}
-				else
-				{
-					attributes[20]	=	0;
-					attributes[21]	=	0;
-					attributes[22]	=	0;
-					attributes[23]	=	0;
-				}
-			
-				attributes[24]	=	0;
-				attributes[25]	=	0;
-			
-				if (!wglChoosePixelFormatARB(hDC, attributes, attribsFloat, 1, &pixelFormat, &numFormats))
-				{
-					Printf("R_OPENGL: Couldn't choose pixel format. Retrying in compatibility mode\n");
-					goto oldmethod;
-				}
-			
-				if (numFormats == 0)
-				{
-					Printf("R_OPENGL: No valid pixel formats found. Retrying in compatibility mode\n");
-					goto oldmethod;
-				}
-
-				break;
-			}
-			else
-			{
-			oldmethod:
-				// If wglChoosePixelFormatARB is not found we have to do it the old fashioned way.
-				static PIXELFORMATDESCRIPTOR pfd = {
-					sizeof(PIXELFORMATDESCRIPTOR),
-						1,
-						PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
-						PFD_TYPE_RGBA,
-						32, // color depth
-						0, 0, 0, 0, 0, 0,
-						0,
-						0,
-						0,
-						0, 0, 0, 0,
-						32, // z depth
-						stencil*8, // stencil buffer
-						0,
-						PFD_MAIN_PLANE,
-						0,
-						0, 0, 0
-				};
-
-				pixelFormat = ChoosePixelFormat(hDC, &pfd);
-				DescribePixelFormat(hDC, pixelFormat, sizeof(pfd), &pfd);
-
-				if (pfd.dwFlags & PFD_GENERIC_FORMAT)
-				{
-					if (!allowsoftware)
-					{
-						if (stencil==0)
-						{
-							// not accelerated!
-							Printf("R_OPENGL: OpenGL driver not accelerated!  Falling back to software renderer.\n");
-							return false;
-						}
-						else
-						{
-							Printf("R_OPENGL: OpenGL driver not accelerated! Retrying in compatibility mode\n");
-							continue;
-						}
-					}
-				}
-				break;
-			}
-		}
-	}
-	else
-	{
-		// Use the cheapest mode available and let's hope the driver can handle this...
-		stencil=0;
-
-		// If wglChoosePixelFormatARB is not found we have to do it the old fashioned way.
-		static PIXELFORMATDESCRIPTOR pfd = {
-			sizeof(PIXELFORMATDESCRIPTOR),
-				1,
-				PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
-				PFD_TYPE_RGBA,
-				16, // color depth
-				0, 0, 0, 0, 0, 0,
-				0,
-				0,
-				0,
-				0, 0, 0, 0,
-				16, // z depth
-				0, // stencil buffer
-				0,
-				PFD_MAIN_PLANE,
-				0,
-				0, 0, 0
-		};
-
-		pixelFormat = ChoosePixelFormat(hDC, &pfd);
-		DescribePixelFormat(hDC, pixelFormat, sizeof(pfd), &pfd);
-
-		if (pfd.dwFlags & PFD_GENERIC_FORMAT)
-		{
-			if (!allowsoftware)
-			{
-				Printf("R_OPENGL: OpenGL driver not accelerated! Falling back to software renderer.\n");
-				return false;
-			}
-		}
-	}
-	if (stencil==0)
-	{
-		gl->flags|=RFL_NOSTENCIL;
-	}
-
-	if (!SetPixelFormat(hDC, pixelFormat, NULL))
-	{
-		Printf("R_OPENGL: Couldn't set pixel format.\n");
-		return false;
-	}
-	return true;
-}
-#else
-
-static bool SetupPixelFormat(bool allowsoftware, bool nostencil, int multisample)
-{
-	int stencil;
-	
-	if (!nostencil)
-	{
-		stencil=1;
-		SDL_GL_SetAttribute( SDL_GL_RED_SIZE,  8 );
-		SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE,  8 );
-		SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE,  8 );
-		SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE,  8 );
-		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE,  24 );
-		SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE,  8 );
-//		SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER,  1 );
-		if (multisample > 0) {
-			SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
-			SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, multisample );
-		}
-	}
-	else
-	{
-		// Use the cheapest mode available and let's hope the driver can handle this...
-		stencil=0;
-
-		SDL_GL_SetAttribute( SDL_GL_RED_SIZE,  4 );
-		SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE,  4 );
-		SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE,  4 );
-		SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE,  4 );
-		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE,  16 );
-		//SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER,  1 )*/
-	}
-	if (stencil==0)
-	{
-		gl->flags|=RFL_NOSTENCIL;
-	}
-	return true;
-}
-#endif
-
-
-//==========================================================================
-//
-// 
-//
-//==========================================================================
-
-#if !defined (unix) && !defined (__APPLE__)
-CVAR(Bool, gl_debug, false, 0)
-
-static bool APIENTRY InitHardware (HWND Window, bool allowsoftware, bool nostencil, int multisample)
-{
-	m_Window=Window;
-	m_hDC = GetDC(Window);
-
-	if (!SetupPixelFormat(m_hDC, allowsoftware, nostencil, multisample))
-	{
-		Printf ("R_OPENGL: Reverting to software mode...\n");
-		return false;
-	}
-
-	m_hRC = 0;
-	if (wglCreateContextAttribsARB != NULL)
-	{
-		int ctxAttribs[] = {
-			WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
-			WGL_CONTEXT_MINOR_VERSION_ARB, 3,
-			WGL_CONTEXT_FLAGS_ARB, gl_debug? WGL_CONTEXT_DEBUG_BIT_ARB : 0,
-			WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
-			0
-		};
-
-		m_hRC = wglCreateContextAttribsARB(m_hDC, 0, ctxAttribs);
-	}
-	if (m_hRC == 0)
-	{
-		m_hRC = wglCreateContext(m_hDC);
-	}
-
-	if (m_hRC == NULL)
-	{
-		Printf ("R_OPENGL: Couldn't create render context. Reverting to software mode...\n");
-		return false;
-	}
-
-	wglMakeCurrent(m_hDC, m_hRC);
-	return true;
-}
-
-#else
-static bool APIENTRY InitHardware (bool allowsoftware, bool nostencil, int multisample)
-{
-	if (!SetupPixelFormat(allowsoftware, nostencil, multisample))
-	{
-		Printf ("R_OPENGL: Reverting to software mode...\n");
-		return false;
-	}
-	return true;
-}
-#endif
-
-
-//==========================================================================
-//
-// 
-//
-//==========================================================================
-
-#if !defined (unix) && !defined (__APPLE__)
-static void APIENTRY Shutdown()
-{
-	if (m_hRC)
-	{
-		wglMakeCurrent(0, 0);
-		wglDeleteContext(m_hRC);
-	}
-	if (m_hDC) ReleaseDC(m_Window, m_hDC);
-}
-
-
-static bool APIENTRY SetFullscreen(const char *devicename, int w, int h, int bits, int hz)
-{
-	DEVMODE dm;
-
-	if (w==0)
-	{
-		ChangeDisplaySettingsEx(devicename, 0, 0, 0, 0);
-	}
-	else
-	{
-		dm.dmSize = sizeof(DEVMODE);
-		dm.dmSpecVersion = DM_SPECVERSION;//Somebody owes me...
-		dm.dmDriverExtra = 0;//...1 hour of my life back
-		dm.dmPelsWidth = w;
-		dm.dmPelsHeight = h;
-		dm.dmBitsPerPel = bits;
-		dm.dmDisplayFrequency = hz;
-		dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
-		if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettingsEx(devicename, &dm, 0, CDS_FULLSCREEN, 0))
-		{
-			dm.dmFields &= ~DM_DISPLAYFREQUENCY;
-			return DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(devicename, &dm, 0, CDS_FULLSCREEN, 0);
-		}
-	}
-	return true;
-}
-#endif
-//==========================================================================
-//
-// 
-//
-//==========================================================================
-
-static void APIENTRY iSwapBuffers()
-{
-#if !defined (unix) && !defined (__APPLE__)
-	SwapBuffers(m_hDC);
-#else
-	SDL_GL_SwapBuffers ();
-#endif
-}
-
-static BOOL APIENTRY SetVSync( int vsync )
-{
-#if defined (__APPLE__)
-	return kCGLNoError == CGLSetParameter( CGLGetCurrentContext(), kCGLCPSwapInterval, &vsync );
-#else // !__APPLE__
-	// empty placeholder
-	return false;
-#endif // __APPLE__
-}
-
-//==========================================================================
-//
-// 
-//
-//==========================================================================
-
 static void APIENTRY glBlendEquationDummy (GLenum mode)
 {
 	// If this is not supported all non-existent modes are
@@ -969,12 +434,6 @@ static void APIENTRY SetTextureMode(int type)
 //
 //==========================================================================
 
-/*
-extern "C"
-{
-
-__declspec(dllexport) 
-*/
 void APIENTRY GetContext(RenderContext & gl)
 {
 	::gl=&gl;
@@ -984,14 +443,6 @@ void APIENTRY GetContext(RenderContext & gl)
 	gl.LoadExtensions = LoadExtensions;
 	gl.SetTextureMode = SetTextureMode;
 	gl.PrintStartupLog = PrintStartupLog;
-	gl.InitHardware = InitHardware;
-#if !defined (unix) && !defined (__APPLE__)
-	gl.Shutdown = Shutdown;
-#endif
-	gl.SwapBuffers = iSwapBuffers;
-#if !defined (unix) && !defined (__APPLE__)
-	gl.SetFullscreen = SetFullscreen;
-#endif
 
 	gl.Begin = glBegin;
 	gl.End = glEnd;
@@ -1069,13 +520,6 @@ void APIENTRY GetContext(RenderContext & gl)
 	gl.Flush = glFlush;
 
 	gl.BlendEquation = glBlendEquationDummy;
-	gl.SetVSync = SetVSync;
-
-#if !defined (unix) && !defined (__APPLE__)
-	ReadInitExtensions();
-	//GL is not yet inited in UNIX version, read them later in LoadExtensions
-#endif
-
 }
 
 
diff --git a/src/gl/system/gl_interface.h b/src/gl/system/gl_interface.h
index a6c583343d..5473f3e03e 100644
--- a/src/gl/system/gl_interface.h
+++ b/src/gl/system/gl_interface.h
@@ -70,16 +70,6 @@ struct RenderContext
 	void (APIENTRY * LoadExtensions) ();
 	void (APIENTRY * SetTextureMode) (int type);
 	void (APIENTRY * PrintStartupLog) ();
-	BOOL (APIENTRY * SetVSync) (int on);
-#if !defined (unix) && !defined (__APPLE__)
-	bool (APIENTRY * InitHardware) (HWND, bool allowsoftware, bool nostencil, int multisample);
-	void (APIENTRY * Shutdown) ();
-#else
-	bool (APIENTRY * InitHardware) (bool allowsoftware, bool nostencil, int multisample);
-#endif
-	void (APIENTRY * SwapBuffers) ();
-	bool (APIENTRY * SetFullscreen) (const char *devicename, int w, int h, int bits, int hz);
-
 
 	void (APIENTRY * Begin) (GLenum mode);
 	void (APIENTRY * End) (void);
@@ -247,8 +237,6 @@ struct RenderContext
 };
 
 
-typedef void (APIENTRY * GetContextProc)(RenderContext & gl);
-
 void APIENTRY GetContext(RenderContext & gl);
 
 #endif
diff --git a/src/gl/system/gl_system.h b/src/gl/system/gl_system.h
index 5dc6cf5b5b..d2430bd638 100644
--- a/src/gl/system/gl_system.h
+++ b/src/gl/system/gl_system.h
@@ -5,8 +5,10 @@
 //#define __wtypes_h__
 #define WIN32_LEAN_AND_MEAN
 #define _WIN32_WINDOWS 0x410
+#ifndef _WIN32_WINNT
 #define _WIN32_WINNT 0x0501			// Support the mouse wheel and session notification.
 #define _WIN32_IE 0x0500
+#endif
 #define DIRECTINPUT_VERSION 0x800
 #define DIRECTDRAW_VERSION 0x0300
 
diff --git a/src/sdl/sdlglvideo.cpp b/src/sdl/sdlglvideo.cpp
index 9ee54b4e8a..3285b8ed5c 100644
--- a/src/sdl/sdlglvideo.cpp
+++ b/src/sdl/sdlglvideo.cpp
@@ -279,6 +279,67 @@ bool SDLGLVideo::SetResolution (int width, int height, int bits)
 	return true;	// We must return true because the old video context no longer exists.
 }
 
+//==========================================================================
+//
+// 
+//
+//==========================================================================
+
+bool SDLGLVideo::SetupPixelFormat(bool allowsoftware, bool nostencil, int multisample)
+{
+	int stencil;
+	
+	if (!nostencil)
+	{
+		stencil=1;
+		SDL_GL_SetAttribute( SDL_GL_RED_SIZE,  8 );
+		SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE,  8 );
+		SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE,  8 );
+		SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE,  8 );
+		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE,  24 );
+		SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE,  8 );
+//		SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER,  1 );
+		if (multisample > 0) {
+			SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
+			SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, multisample );
+		}
+	}
+	else
+	{
+		// Use the cheapest mode available and let's hope the driver can handle this...
+		stencil=0;
+
+		SDL_GL_SetAttribute( SDL_GL_RED_SIZE,  4 );
+		SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE,  4 );
+		SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE,  4 );
+		SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE,  4 );
+		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE,  16 );
+		//SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER,  1 )*/
+	}
+	if (stencil==0)
+	{
+		gl.flags|=RFL_NOSTENCIL;
+	}
+	return true;
+}
+
+//==========================================================================
+//
+// 
+//
+//==========================================================================
+
+bool SDLGLVideo::InitHardware (bool allowsoftware, bool nostencil, int multisample)
+{
+	if (!SetupPixelFormat(allowsoftware, nostencil, multisample))
+	{
+		Printf ("R_OPENGL: Reverting to software mode...\n");
+		return false;
+	}
+	return true;
+}
+
+
 // FrameBuffer implementation -----------------------------------------------
 
 SDLGLFB::SDLGLFB (void *, int width, int height, int, int, bool fullscreen)
@@ -294,7 +355,7 @@ SDLGLFB::SDLGLFB (void *, int width, int height, int, int, bool fullscreen)
 
 	UpdatePending = false;
 	
-	if (!gl.InitHardware(false, gl_vid_compatibility, localmultisample))
+	if (!static_cast<SDLGLVideo*>(Video)->InitHardware(false, gl_vid_compatibility, localmultisample))
 	{
 		vid_renderer = 0;
 		return;
@@ -335,6 +396,9 @@ SDLGLFB::~SDLGLFB ()
 	}
 }
 
+
+
+
 void SDLGLFB::InitializeState() 
 {
 	int value = 0;
@@ -417,3 +481,8 @@ void SDLGLFB::NewRefreshRate ()
 {
 }
 
+void SDLGLFB::SwapBuffers()
+{
+	SDL_GL_SwapBuffers ();
+}
+
diff --git a/src/sdl/sdlglvideo.h b/src/sdl/sdlglvideo.h
index 35175e421d..4fbdf3e9a3 100644
--- a/src/sdl/sdlglvideo.h
+++ b/src/sdl/sdlglvideo.h
@@ -27,6 +27,9 @@ class SDLGLVideo : public IVideo
 	bool NextMode (int *width, int *height, bool *letterbox);
 	bool SetResolution (int width, int height, int bits);
 
+	bool SetupPixelFormat(bool allowsoftware, bool nostencil, int multisample);
+	bool InitHardware (bool allowsoftware, bool nostencil, int multisample);
+
 private:
 	int IteratorMode;
 	int IteratorBits;
@@ -50,6 +53,7 @@ public:
 	bool IsFullscreen ();
 
 	virtual void SetVSync( bool vsync );
+	void SwapBuffers();
 	
 	void NewRefreshRate ();
 
diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp
index cd009c206f..e9d1bc5e6a 100644
--- a/src/win32/hardware.cpp
+++ b/src/win32/hardware.cpp
@@ -56,12 +56,15 @@ EXTERN_CVAR (Float, vid_winscale)
 CVAR(Int, win_x, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
 CVAR(Int, win_y, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
 
-#include "win32gliface.h"
+extern HWND Window;
 
 bool ForceWindowed;
 
 IVideo *Video;
 
+// do not include GL headers here, only declare the necessary functions.
+IVideo *gl_CreateVideo();
+FRenderer *gl_CreateInterface();
 
 void I_RestartRenderer();
 int currentrenderer = -1;
@@ -134,7 +137,7 @@ void I_InitGraphics ()
 	ticker.SetGenericRepDefault (val, CVAR_Bool);
 
 	//currentrenderer = vid_renderer;
-	if (currentrenderer==1) Video = new Win32GLVideo(0);
+	if (currentrenderer==1) Video = gl_CreateVideo();
 	else Video = new Win32Video (0);
 
 	if (Video == NULL)
diff --git a/src/win32/win32gliface.cpp b/src/win32/win32gliface.cpp
index af6bf42cde..e13dce63d6 100644
--- a/src/win32/win32gliface.cpp
+++ b/src/win32/win32gliface.cpp
@@ -27,6 +27,8 @@ CUSTOM_CVAR(Int, gl_vid_multisample, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_
 	Printf("This won't take effect until "GAMENAME" is restarted.\n");
 }
 
+CVAR(Bool, gl_debug, false, 0)
+
 RenderContext gl;
 
 
@@ -53,6 +55,7 @@ Win32GLVideo::Win32GLVideo(int parm) : m_Modes(NULL), m_IsFullscreen(false)
 	GetDisplayDeviceName();
 	MakeModesList();
 	GetContext(gl);
+	SetPixelFormat();
 
 }
 
@@ -314,11 +317,11 @@ bool Win32GLVideo::GoFullscreen(bool yes)
 
 	if (yes)
 	{
-		gl.SetFullscreen(m_DisplayDeviceName, m_DisplayWidth, m_trueHeight, m_DisplayBits, m_DisplayHz);
+		SetFullscreen(m_DisplayDeviceName, m_DisplayWidth, m_trueHeight, m_DisplayBits, m_DisplayHz);
 	}
 	else
 	{
-		gl.SetFullscreen(m_DisplayDeviceName, 0,0,0,0);
+		SetFullscreen(m_DisplayDeviceName, 0,0,0,0);
 	}
 	return yes;
 }
@@ -465,6 +468,429 @@ void Win32GLVideo::DumpAdapters()
 //
 //==========================================================================
 
+HWND Win32GLVideo::InitDummy()
+{
+	HMODULE g_hInst = GetModuleHandle(NULL);
+	HWND dummy;
+	//Create a rect structure for the size/position of the window
+	RECT windowRect;
+	windowRect.left = 0;
+	windowRect.right = 64;
+	windowRect.top = 0;
+	windowRect.bottom = 64;
+
+	//Window class structure
+	WNDCLASS wc;
+
+	//Fill in window class struct
+	wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
+	wc.lpfnWndProc = (WNDPROC) DefWindowProc;
+	wc.cbClsExtra = 0;
+	wc.cbWndExtra = 0;
+	wc.hInstance = g_hInst;
+	wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
+	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+	wc.hbrBackground = NULL;
+	wc.lpszMenuName = NULL;
+	wc.lpszClassName = "GZDoomOpenGLDummyWindow";
+
+	//Register window class
+	if(!RegisterClass(&wc))
+	{
+		return 0;
+	}
+
+	//Set window style & extended style
+	DWORD style, exStyle;
+	exStyle = WS_EX_CLIENTEDGE;
+	style = WS_SYSMENU | WS_BORDER | WS_CAPTION;// | WS_VISIBLE;
+
+	//Adjust the window size so that client area is the size requested
+	AdjustWindowRectEx(&windowRect, style, false, exStyle);
+
+	//Create Window
+	if(!(dummy = CreateWindowEx(exStyle,
+		"GZDoomOpenGLDummyWindow",
+		"GZDOOM",
+		WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style,
+		0, 0,
+		windowRect.right-windowRect.left,
+		windowRect.bottom-windowRect.top,
+		NULL, NULL,
+		g_hInst,
+		NULL)))
+	{
+		UnregisterClass("GZDoomOpenGLDummyWindow", g_hInst);
+		return 0;
+	}
+	ShowWindow(dummy, SW_HIDE);
+
+	return dummy;
+}
+
+//==========================================================================
+//
+// 
+//
+//==========================================================================
+
+void Win32GLVideo::ShutdownDummy(HWND dummy)
+{
+	DestroyWindow(dummy);
+	UnregisterClass("GZDoomOpenGLDummyWindow", GetModuleHandle(NULL));
+}
+
+
+//==========================================================================
+//
+// 
+//
+//==========================================================================
+
+bool Win32GLVideo::SetPixelFormat()
+{
+	HDC hDC;
+	HGLRC hRC;
+	HWND dummy;
+
+	PIXELFORMATDESCRIPTOR pfd = {
+		sizeof(PIXELFORMATDESCRIPTOR),
+			1,
+			PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
+			PFD_TYPE_RGBA,
+			32, // color depth
+			0, 0, 0, 0, 0, 0,
+			0,
+			0,
+			0,
+			0, 0, 0, 0,
+			16, // z depth
+			0, // stencil buffer
+			0,
+			PFD_MAIN_PLANE,
+			0,
+			0, 0, 0
+	};
+
+	int pixelFormat;
+
+	// we have to create a dummy window to init stuff from or the full init stuff fails
+	dummy = InitDummy();
+
+	hDC = GetDC(dummy);
+	pixelFormat = ChoosePixelFormat(hDC, &pfd);
+	DescribePixelFormat(hDC, pixelFormat, sizeof(pfd), &pfd);
+
+	::SetPixelFormat(hDC, pixelFormat, &pfd);
+
+	hRC = wglCreateContext(hDC);
+	wglMakeCurrent(hDC, hRC);
+
+	wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
+	wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
+	// any extra stuff here?
+
+	wglMakeCurrent(NULL, NULL);
+	wglDeleteContext(hRC);
+	ReleaseDC(dummy, hDC);
+	ShutdownDummy(dummy);
+
+	return true;
+}
+
+//==========================================================================
+//
+// 
+//
+//==========================================================================
+
+bool Win32GLVideo::SetupPixelFormat(bool allowsoftware, bool nostencil, int multisample)
+{
+	int colorDepth;
+	HDC deskDC;
+	int attributes[26];
+	int pixelFormat;
+	unsigned int numFormats;
+	float attribsFloat[] = {0.0f, 0.0f};
+	int stencil;
+	
+	deskDC = GetDC(GetDesktopWindow());
+	colorDepth = GetDeviceCaps(deskDC, BITSPIXEL);
+	ReleaseDC(GetDesktopWindow(), deskDC);
+
+	/*
+	if (!nostencil && colorDepth < 32)
+	{
+		Printf("R_OPENGL: Desktop not in 32 bit mode!\n");
+		return false;
+	}
+	*/
+
+	if (!nostencil)
+	{
+		for (stencil=1;stencil>=0;stencil--)
+		{
+			if (wglChoosePixelFormatARB && stencil)
+			{
+				attributes[0]	=	WGL_RED_BITS_ARB; //bits
+				attributes[1]	=	8;
+				attributes[2]	=	WGL_GREEN_BITS_ARB; //bits
+				attributes[3]	=	8;
+				attributes[4]	=	WGL_BLUE_BITS_ARB; //bits
+				attributes[5]	=	8;
+				attributes[6]	=	WGL_ALPHA_BITS_ARB;
+				attributes[7]	=	8;
+				attributes[8]	=	WGL_DEPTH_BITS_ARB;
+				attributes[9]	=	24;
+				attributes[10]	=	WGL_STENCIL_BITS_ARB;
+				attributes[11]	=	8;
+			
+				attributes[12]	=	WGL_DRAW_TO_WINDOW_ARB;	//required to be true
+				attributes[13]	=	true;
+				attributes[14]	=	WGL_SUPPORT_OPENGL_ARB;
+				attributes[15]	=	true;
+				attributes[16]	=	WGL_DOUBLE_BUFFER_ARB;
+				attributes[17]	=	true;
+			
+				attributes[18]	=	WGL_ACCELERATION_ARB;	//required to be FULL_ACCELERATION_ARB
+				if (allowsoftware)
+				{
+					attributes[19]	=	WGL_NO_ACCELERATION_ARB;
+				}
+				else
+				{
+					attributes[19]	=	WGL_FULL_ACCELERATION_ARB;
+				}
+			
+				if (multisample > 0)
+				{
+					attributes[20]	=	WGL_SAMPLE_BUFFERS_ARB;
+					attributes[21]	=	true;
+					attributes[22]	=	WGL_SAMPLES_ARB;
+					attributes[23]	=	multisample;
+				}
+				else
+				{
+					attributes[20]	=	0;
+					attributes[21]	=	0;
+					attributes[22]	=	0;
+					attributes[23]	=	0;
+				}
+			
+				attributes[24]	=	0;
+				attributes[25]	=	0;
+			
+				if (!wglChoosePixelFormatARB(m_hDC, attributes, attribsFloat, 1, &pixelFormat, &numFormats))
+				{
+					Printf("R_OPENGL: Couldn't choose pixel format. Retrying in compatibility mode\n");
+					goto oldmethod;
+				}
+			
+				if (numFormats == 0)
+				{
+					Printf("R_OPENGL: No valid pixel formats found. Retrying in compatibility mode\n");
+					goto oldmethod;
+				}
+
+				break;
+			}
+			else
+			{
+			oldmethod:
+				// If wglChoosePixelFormatARB is not found we have to do it the old fashioned way.
+				static PIXELFORMATDESCRIPTOR pfd = {
+					sizeof(PIXELFORMATDESCRIPTOR),
+						1,
+						PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
+						PFD_TYPE_RGBA,
+						32, // color depth
+						0, 0, 0, 0, 0, 0,
+						0,
+						0,
+						0,
+						0, 0, 0, 0,
+						32, // z depth
+						stencil*8, // stencil buffer
+						0,
+						PFD_MAIN_PLANE,
+						0,
+						0, 0, 0
+				};
+
+				pixelFormat = ChoosePixelFormat(m_hDC, &pfd);
+				DescribePixelFormat(m_hDC, pixelFormat, sizeof(pfd), &pfd);
+
+				if (pfd.dwFlags & PFD_GENERIC_FORMAT)
+				{
+					if (!allowsoftware)
+					{
+						if (stencil==0)
+						{
+							// not accelerated!
+							Printf("R_OPENGL: OpenGL driver not accelerated!  Falling back to software renderer.\n");
+							return false;
+						}
+						else
+						{
+							Printf("R_OPENGL: OpenGL driver not accelerated! Retrying in compatibility mode\n");
+							continue;
+						}
+					}
+				}
+				break;
+			}
+		}
+	}
+	else
+	{
+		// Use the cheapest mode available and let's hope the driver can handle this...
+		stencil=0;
+
+		// If wglChoosePixelFormatARB is not found we have to do it the old fashioned way.
+		static PIXELFORMATDESCRIPTOR pfd = {
+			sizeof(PIXELFORMATDESCRIPTOR),
+				1,
+				PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
+				PFD_TYPE_RGBA,
+				16, // color depth
+				0, 0, 0, 0, 0, 0,
+				0,
+				0,
+				0,
+				0, 0, 0, 0,
+				16, // z depth
+				0, // stencil buffer
+				0,
+				PFD_MAIN_PLANE,
+				0,
+				0, 0, 0
+		};
+
+		pixelFormat = ChoosePixelFormat(m_hDC, &pfd);
+		DescribePixelFormat(m_hDC, pixelFormat, sizeof(pfd), &pfd);
+
+		if (pfd.dwFlags & PFD_GENERIC_FORMAT)
+		{
+			if (!allowsoftware)
+			{
+				Printf("R_OPENGL: OpenGL driver not accelerated! Falling back to software renderer.\n");
+				return false;
+			}
+		}
+	}
+	if (stencil==0)
+	{
+		gl.flags|=RFL_NOSTENCIL;
+	}
+
+	if (!::SetPixelFormat(m_hDC, pixelFormat, NULL))
+	{
+		Printf("R_OPENGL: Couldn't set pixel format.\n");
+		return false;
+	}
+	return true;
+}
+
+//==========================================================================
+//
+// 
+//
+//==========================================================================
+
+bool Win32GLVideo::InitHardware (HWND Window, bool allowsoftware, bool nostencil, int multisample)
+{
+	m_Window=Window;
+	m_hDC = GetDC(Window);
+
+	if (!SetupPixelFormat(allowsoftware, nostencil, multisample))
+	{
+		Printf ("R_OPENGL: Reverting to software mode...\n");
+		return false;
+	}
+
+	m_hRC = 0;
+	if (wglCreateContextAttribsARB != NULL)
+	{
+		int ctxAttribs[] = {
+			WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
+			WGL_CONTEXT_MINOR_VERSION_ARB, 3,
+			WGL_CONTEXT_FLAGS_ARB, gl_debug? WGL_CONTEXT_DEBUG_BIT_ARB : 0,
+			WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
+			0
+		};
+
+		m_hRC = wglCreateContextAttribsARB(m_hDC, 0, ctxAttribs);
+	}
+	if (m_hRC == 0)
+	{
+		m_hRC = wglCreateContext(m_hDC);
+	}
+
+	if (m_hRC == NULL)
+	{
+		Printf ("R_OPENGL: Couldn't create render context. Reverting to software mode...\n");
+		return false;
+	}
+
+	wglMakeCurrent(m_hDC, m_hRC);
+	return true;
+}
+
+//==========================================================================
+//
+// 
+//
+//==========================================================================
+
+void Win32GLVideo::Shutdown()
+{
+	if (m_hRC)
+	{
+		wglMakeCurrent(0, 0);
+		wglDeleteContext(m_hRC);
+	}
+	if (m_hDC) ReleaseDC(m_Window, m_hDC);
+}
+
+//==========================================================================
+//
+// 
+//
+//==========================================================================
+
+bool Win32GLVideo::SetFullscreen(const char *devicename, int w, int h, int bits, int hz)
+{
+	DEVMODE dm;
+
+	if (w==0)
+	{
+		ChangeDisplaySettingsEx(devicename, 0, 0, 0, 0);
+	}
+	else
+	{
+		dm.dmSize = sizeof(DEVMODE);
+		dm.dmSpecVersion = DM_SPECVERSION;//Somebody owes me...
+		dm.dmDriverExtra = 0;//...1 hour of my life back
+		dm.dmPelsWidth = w;
+		dm.dmPelsHeight = h;
+		dm.dmBitsPerPel = bits;
+		dm.dmDisplayFrequency = hz;
+		dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
+		if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettingsEx(devicename, &dm, 0, CDS_FULLSCREEN, 0))
+		{
+			dm.dmFields &= ~DM_DISPLAYFREQUENCY;
+			return DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(devicename, &dm, 0, CDS_FULLSCREEN, 0);
+		}
+	}
+	return true;
+}
+
+//==========================================================================
+//
+// 
+//
+//==========================================================================
+
 IMPLEMENT_ABSTRACT_CLASS(Win32GLFrameBuffer)
 
 //==========================================================================
@@ -528,7 +954,7 @@ Win32GLFrameBuffer::Win32GLFrameBuffer(void *hMonitor, int width, int height, in
 
 	if (fullscreen)
 	{
-		MoveWindow(Window, monX, monY, width, static_cast<Win32GLVideo *>(Video)->GetTrueHeight(), FALSE);
+		MoveWindow(Window, monX, monY, width, GetTrueHeight(), FALSE);
 
 		// And now, seriously, it IS in the right place. Promise.
 	}
@@ -539,12 +965,14 @@ Win32GLFrameBuffer::Win32GLFrameBuffer(void *hMonitor, int width, int height, in
 		I_RestoreWindowedPos();
 	}
 
-	if (!gl.InitHardware(Window, false, gl_vid_compatibility, localmultisample))
+	if (!static_cast<Win32GLVideo *>(Video)->InitHardware(Window, false, gl_vid_compatibility, localmultisample))
 	{
 		vid_renderer = 0;
 		return;
 	}
 
+	vsyncfunc = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
+
 	HDC hDC = GetDC(Window);
 	m_supportsGamma = !!GetDeviceGammaRamp(hDC, (void *)m_origGamma);
 	ReleaseDC(Window, hDC);
@@ -566,7 +994,7 @@ Win32GLFrameBuffer::~Win32GLFrameBuffer()
 	}
 	I_SaveWindowedPos();
 
-	gl.SetFullscreen(m_displayDeviceName, 0,0,0,0);
+	static_cast<Win32GLVideo *>(Video)->SetFullscreen(m_displayDeviceName, 0,0,0,0);
 
 	ShowWindow (Window, SW_SHOW);
 	SetWindowLong(Window, GWL_STYLE, WS_VISIBLE | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW);
@@ -574,7 +1002,7 @@ Win32GLFrameBuffer::~Win32GLFrameBuffer()
 	SetWindowPos(Window, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
 	I_GetEvent();
 
-	gl.Shutdown();
+	static_cast<Win32GLVideo *>(Video)->Shutdown();
 }
 
 
@@ -692,7 +1120,12 @@ void Win32GLFrameBuffer::ReleaseResources ()
 
 void Win32GLFrameBuffer::SetVSync (bool vsync)
 {
-	if (gl.SetVSync!=NULL) gl.SetVSync(vsync);
+	if (vsyncfunc != NULL) vsyncfunc(vsync);
+}
+
+void Win32GLFrameBuffer::SwapBuffers()
+{
+	::SwapBuffers(static_cast<Win32GLVideo *>(Video)->m_hDC);
 }
 
 //==========================================================================
@@ -712,3 +1145,8 @@ void Win32GLFrameBuffer::NewRefreshRate ()
 	}
 }
 
+
+IVideo *gl_CreateVideo()
+{
+	return new Win32GLVideo(0);
+}
\ No newline at end of file
diff --git a/src/win32/win32gliface.h b/src/win32/win32gliface.h
index ba4ea001d7..e4d70ba431 100644
--- a/src/win32/win32gliface.h
+++ b/src/win32/win32gliface.h
@@ -1,17 +1,9 @@
 #ifndef __WIN32GLIFACE_H__
 #define __WIN32GLIFACE_H__
 
-/*
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <gl/gl.h>
-
-#include "gl/glext.h"
-#include "gl/wglext.h"
-*/
-
-#include "win32iface.h"
+#include "gl/system/gl_system.h"
 #include "hardware.h"
+#include "win32iface.h"
 #include "v_video.h"
 #include "tarray.h"
 
@@ -50,6 +42,13 @@ public:
 	DFrameBuffer *CreateFrameBuffer (int width, int height, bool fs, DFrameBuffer *old);
 	virtual bool SetResolution (int width, int height, int bits);
 	void DumpAdapters();
+	bool InitHardware (HWND Window, bool allowsoftware, bool nostencil, int multisample);
+	void Shutdown();
+	bool SetFullscreen(const char *devicename, int w, int h, int bits, int hz);
+
+	PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; // = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
+	PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
+	HDC m_hDC;
 
 protected:
 	struct ModeInfo
@@ -78,6 +77,14 @@ protected:
 	char *m_DisplayDeviceName;
 	HMONITOR m_hMonitor;
 
+	HWND m_Window;
+	HGLRC m_hRC;
+
+	HWND InitDummy();
+	void ShutdownDummy(HWND dummy);
+	bool SetPixelFormat();
+	bool SetupPixelFormat(bool allowsoftware, bool nostencil, int multisample);
+
 	void GetDisplayDeviceName();
 	void MakeModesList();
 	void AddMode(int x, int y, int bits, int baseHeight, int refreshHz);
@@ -100,6 +107,8 @@ public:
 	Win32GLFrameBuffer(void *hMonitor, int width, int height, int bits, int refreshHz, bool fullscreen);
 	virtual ~Win32GLFrameBuffer();
 
+	PFNWGLSWAPINTERVALEXTPROC vsyncfunc;
+
 	// unused but must be defined
 	virtual void Blank ();
 	virtual bool PaintToWindow ();
@@ -109,10 +118,11 @@ public:
 	virtual void ReleaseResources ();
 
 	void SetVSync (bool vsync);
+	void SwapBuffers();
 	void NewRefreshRate ();
 
 
-	int GetTrueHeight() { return static_cast<Win32GLVideo*>(Video)->GetTrueHeight(); }
+	int GetTrueHeight() { return static_cast<Win32GLVideo *>(Video)->GetTrueHeight(); }
 
 	bool Lock(bool buffered);
 	bool Lock ();