changeset 4730:6032ada8b9e5

Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
author dewyatt
date Tue, 25 May 2010 18:53:09 -0400
parents fa77a6429698
children bfc8ad7234b6
files EXCLUDE/GLTSF/GLTSF.sln EXCLUDE/GLTSF/GLTSF.vcxproj EXCLUDE/GLTSF/GLTSF.vcxproj.filters EXCLUDE/GLTSF/include/App.hpp EXCLUDE/GLTSF/include/Video_Mode.hpp EXCLUDE/GLTSF/include/Window.hpp EXCLUDE/GLTSF/include/Window_Listener.hpp EXCLUDE/GLTSF/src/App.cpp EXCLUDE/GLTSF/src/Main.cpp EXCLUDE/GLTSF/src/Video_Mode.cpp EXCLUDE/GLTSF/src/Window.cpp
diffstat 11 files changed, 722 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EXCLUDE/GLTSF/GLTSF.sln	Tue May 25 18:53:09 2010 -0400
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GLTSF", "GLTSF.vcxproj", "{790D58BA-E5F6-4286-A9C6-0DC28779789D}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Release|Win32 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{790D58BA-E5F6-4286-A9C6-0DC28779789D}.Debug|Win32.ActiveCfg = Debug|Win32
+		{790D58BA-E5F6-4286-A9C6-0DC28779789D}.Debug|Win32.Build.0 = Debug|Win32
+		{790D58BA-E5F6-4286-A9C6-0DC28779789D}.Release|Win32.ActiveCfg = Release|Win32
+		{790D58BA-E5F6-4286-A9C6-0DC28779789D}.Release|Win32.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EXCLUDE/GLTSF/GLTSF.vcxproj	Tue May 25 18:53:09 2010 -0400
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{790D58BA-E5F6-4286-A9C6-0DC28779789D}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>GLTSF</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)bin\</OutDir>
+    <IntDir>obj\$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)bin\</OutDir>
+    <IntDir>obj\$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClInclude Include="include\App.hpp" />
+    <ClInclude Include="include\Video_Mode.hpp" />
+    <ClInclude Include="include\Window.hpp" />
+    <ClInclude Include="include\Window_Listener.hpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="src\App.cpp" />
+    <ClCompile Include="src\Main.cpp" />
+    <ClCompile Include="src\Video_Mode.cpp" />
+    <ClCompile Include="src\Window.cpp" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EXCLUDE/GLTSF/GLTSF.vcxproj.filters	Tue May 25 18:53:09 2010 -0400
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="include\App.hpp">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="include\Video_Mode.hpp">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="include\Window.hpp">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="include\Window_Listener.hpp">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="src\App.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\Main.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\Video_Mode.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\Window.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EXCLUDE/GLTSF/include/App.hpp	Tue May 25 18:53:09 2010 -0400
@@ -0,0 +1,26 @@
+#ifndef APP_HPP
+#define APP_HPP
+
+#include "Window.hpp"
+
+class App : public Window_Listener
+{
+public:
+	App();
+	virtual ~App();
+
+	void Initialize();
+	void Finalize();
+
+	void Run();
+
+	virtual void On_Close();
+	virtual void On_Key_Down(int Key);
+	virtual void On_Key_Up(int Key);
+
+private:
+	Window my_Window;
+	bool my_Done;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EXCLUDE/GLTSF/include/Video_Mode.hpp	Tue May 25 18:53:09 2010 -0400
@@ -0,0 +1,30 @@
+#ifndef VIDEO_MODE_HPP
+#define VIDEO_MODE_HPP
+
+#include <cstddef>
+
+class Video_Mode
+{
+public:
+	Video_Mode();
+	Video_Mode(unsigned int The_Width, unsigned int The_Height, unsigned int The_Bits_Per_Pixel);
+
+	static Video_Mode Get_Desktop_Mode();
+
+	static std::size_t Get_Mode_Count();
+	static Video_Mode Get_Mode(std::size_t Index);
+
+	bool Is_Valid() const;
+
+	bool operator==(const Video_Mode &Mode) const;
+	bool operator!=(const Video_Mode &Mode) const;
+
+	unsigned int Width;
+	unsigned int Height;
+	unsigned int Bits_Per_Pixel;
+
+private:
+	static void Initialize_Modes();
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EXCLUDE/GLTSF/include/Window.hpp	Tue May 25 18:53:09 2010 -0400
@@ -0,0 +1,55 @@
+#ifndef WINDOW_HPP
+#define WINDOW_HPP
+
+#include <string>
+
+#define WIN32_LEAN_AND_MEAN
+#include <Windows.h>
+
+#include "Video_Mode.hpp"
+#include "Window_Listener.hpp"
+
+class Window
+{
+public:
+	Window();
+	~Window();
+
+	void Initialize(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen);
+	void Finalize();
+
+	void Set_Listener(Window_Listener *Listener);
+
+	void Show();
+	void Hide();
+
+	void Update();
+	void Display();
+
+private:
+	static const wchar_t *Window_Class_Name;
+
+	void Register_Class();
+	void Unregister_Class();
+
+	void Create_Window(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen);
+	void Destroy_Window();
+
+	void Create_Context(const Video_Mode &Mode);
+	void Destroy_Context();
+
+	void Switch_To_Fullscreen(const Video_Mode &Mode);
+
+	LRESULT Handle_Message(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam);
+	static LRESULT CALLBACK Window_Procedure(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam);
+
+	HWND my_Handle;
+	Video_Mode my_Video_Mode;
+	bool my_Fullscreen;
+	HDC my_Device_Context;
+	HGLRC my_GL_Context;
+	bool my_Class_Registered;
+	Window_Listener *my_Listener;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EXCLUDE/GLTSF/include/Window_Listener.hpp	Tue May 25 18:53:09 2010 -0400
@@ -0,0 +1,13 @@
+#ifndef WINDOW_LISTENER_HPP
+#define WINDOW_LISTENER_HPP
+
+class Window_Listener
+{
+public:
+	virtual void On_Close(){}
+
+	virtual void On_Key_Down(int Key){}
+	virtual void On_Key_Up(int Key){}
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EXCLUDE/GLTSF/src/App.cpp	Tue May 25 18:53:09 2010 -0400
@@ -0,0 +1,56 @@
+#include "App.hpp"
+
+App::App() : my_Done(false)
+{
+
+}
+
+App::~App()
+{
+	Finalize();
+}
+
+void App::Initialize()
+{
+	Finalize();
+
+	my_Window.Initialize(L"GLTSF", Video_Mode(800, 600, 32), false);
+	my_Window.Set_Listener(this);
+	my_Window.Show();
+}
+
+void App::Finalize()
+{
+	my_Window.Finalize();
+}
+
+void App::Run()
+{
+	Initialize();
+	while (!my_Done)
+	{
+		my_Window.Update();
+		my_Window.Display();
+	}
+}
+
+void App::On_Close()
+{
+	my_Done = true;
+	my_Window.Hide();
+}
+
+void App::On_Key_Down(int Key)
+{
+	switch (Key)
+	{
+	case VK_ESCAPE:
+		On_Close();
+		break;
+	}
+}
+
+void App::On_Key_Up(int Key)
+{
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EXCLUDE/GLTSF/src/Main.cpp	Tue May 25 18:53:09 2010 -0400
@@ -0,0 +1,17 @@
+#include "App.hpp"
+#include <stdexcept>
+
+int main(int argc, char *argv[])
+{
+	try
+	{
+		App theApp;
+		theApp.Run();
+	}
+	catch (const std::exception& e)
+	{
+		printf("Error: %s\n", e.what());
+		return 1;
+	}
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EXCLUDE/GLTSF/src/Video_Mode.cpp	Tue May 25 18:53:09 2010 -0400
@@ -0,0 +1,100 @@
+#include "Video_Mode.hpp"
+#include <vector>
+#include <algorithm>
+#define WIN32_LEAN_AND_MEAN
+#include <Windows.h>
+
+namespace
+{
+
+	typedef std::vector<Video_Mode> Video_Mode_List;
+	Video_Mode_List Supported_Modes;
+
+	struct Compare_Modes
+	{
+		bool operator()(const Video_Mode &Mode_1, const Video_Mode &Mode_2) const
+		{
+			if (Mode_1.Bits_Per_Pixel > Mode_2.Bits_Per_Pixel)
+				return true;
+			else if (Mode_1.Bits_Per_Pixel < Mode_2.Bits_Per_Pixel)
+				return false;
+			else if (Mode_1.Width > Mode_2.Width)
+				return true;
+			else if (Mode_1.Width < Mode_2.Width)
+				return false;
+			else
+				return Mode_1.Height > Mode_2.Height;
+		}
+	};
+
+}
+
+Video_Mode::Video_Mode() : Width(0),
+						   Height(0),
+						   Bits_Per_Pixel(0)
+{
+
+}
+
+Video_Mode::Video_Mode(unsigned int The_Width, unsigned int The_Height, unsigned int The_Bits_Per_Pixel)
+	: Width(The_Width),
+	  Height(The_Height),
+	  Bits_Per_Pixel(The_Bits_Per_Pixel)
+{
+
+}
+
+Video_Mode Video_Mode::Get_Desktop_Mode()
+{
+	DEVMODE Device_Mode = {0};
+	Device_Mode.dmSize = sizeof(Device_Mode);
+	EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &Device_Mode);
+	return Video_Mode(Device_Mode.dmPelsWidth, Device_Mode.dmPelsHeight, Device_Mode.dmBitsPerPel);
+}
+
+std::size_t Video_Mode::Get_Mode_Count()
+{
+	Initialize_Modes();
+	return Supported_Modes.size();
+}
+
+Video_Mode Video_Mode::Get_Mode(std::size_t Index)
+{
+	Initialize_Modes();
+	return Supported_Modes[Index];
+}
+
+bool Video_Mode::Is_Valid() const
+{
+	Initialize_Modes();
+	return Supported_Modes.end() != std::find(Supported_Modes.begin(), Supported_Modes.end(), *this);
+}
+
+bool Video_Mode::operator==(const Video_Mode &Mode) const
+{
+	return (Width == Mode.Width
+		&&  Height == Mode.Height
+		&&  Bits_Per_Pixel == Mode.Bits_Per_Pixel);
+}
+
+bool Video_Mode::operator!=(const Video_Mode &Mode) const
+{
+	return !(*this == Mode);
+}
+
+void Video_Mode::Initialize_Modes()
+{
+	static bool Initialized = false;
+	if (!Initialized)
+	{
+		DEVMODE Device_Mode = {0};
+		Device_Mode.dmSize = sizeof(Device_Mode);
+		for (std::size_t i = 0; 0 != EnumDisplaySettings(NULL, i, &Device_Mode); ++i)
+		{
+			Video_Mode Mode(Device_Mode.dmPelsWidth, Device_Mode.dmPelsHeight, Device_Mode.dmBitsPerPel);
+			if (Supported_Modes.end() == std::find(Supported_Modes.begin(), Supported_Modes.end(), Mode))
+				Supported_Modes.push_back(Mode);
+		}
+		std::sort(Supported_Modes.begin(), Supported_Modes.end(), Compare_Modes());
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EXCLUDE/GLTSF/src/Window.cpp	Tue May 25 18:53:09 2010 -0400
@@ -0,0 +1,263 @@
+#include "Window.hpp"
+
+#pragma comment(lib, "opengl32.lib")
+
+const wchar_t *Window::Window_Class_Name = L"GLTSF";
+
+Window::Window() : my_Handle(0),
+				   my_Device_Context(0),
+				   my_GL_Context(0),
+				   my_Class_Registered(false),
+				   my_Listener(0)
+{
+
+}
+
+Window::~Window()
+{
+	Finalize();
+}
+
+void Window::Initialize(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen)
+{
+	Finalize();
+
+	my_Video_Mode = Mode;
+	if (!my_Video_Mode.Is_Valid())
+		throw std::runtime_error("Invalid video mode");
+
+	my_Fullscreen = Fullscreen;
+	Register_Class();
+	Create_Window(Title, Mode, Fullscreen);
+}
+
+void Window::Finalize()
+{
+	Destroy_Window();
+	Unregister_Class();
+}
+
+void Window::Set_Listener(Window_Listener *Listener)
+{
+	my_Listener = Listener;
+}
+
+void Window::Register_Class()
+{
+	WNDCLASSEXW Window_Class = {0};
+	Window_Class.cbSize = sizeof(Window_Class);
+	Window_Class.style = 0;
+	Window_Class.lpfnWndProc = &Window::Window_Procedure;
+	Window_Class.cbClsExtra = 0;
+	Window_Class.cbWndExtra = 0;
+	Window_Class.hInstance = GetModuleHandle(NULL);
+	Window_Class.hIcon = NULL;
+	Window_Class.hCursor = NULL;
+	Window_Class.hbrBackground = NULL;
+	Window_Class.lpszMenuName = NULL;
+	Window_Class.lpszClassName = Window_Class_Name;
+	Window_Class.hIconSm = NULL;
+	if (0 == RegisterClassExW(&Window_Class))
+		throw std::runtime_error("Failed to register window class");
+
+	my_Class_Registered = true;
+}
+
+void Window::Unregister_Class()
+{
+	if (my_Class_Registered)
+	{
+		if (0 == UnregisterClassW(Window_Class_Name, GetModuleHandle(NULL)))
+			printf("Warning: Failed to unregister window class\n");
+
+		my_Class_Registered = false;
+	}
+}
+
+void Window::Create_Window(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen)
+{
+	HDC Screen_DC = GetDC(NULL);
+	int Left = (GetDeviceCaps(Screen_DC, HORZRES) - my_Video_Mode.Width) / 2;
+	int Top = (GetDeviceCaps(Screen_DC, VERTRES) - my_Video_Mode.Height) / 2;
+	int Width = my_Video_Mode.Width;
+	int Height = my_Video_Mode.Height;
+	ReleaseDC(NULL, Screen_DC);
+
+	DWORD Style = WS_OVERLAPPEDWINDOW;
+	if (!my_Fullscreen)
+	{
+		RECT Rect = {0, 0, Width, Height};
+		AdjustWindowRect(&Rect, Style, false);
+		Width = Rect.right - Rect.left;
+		Height = Rect.bottom - Rect.top;
+	}
+	my_Handle = CreateWindowW(Window_Class_Name, Title.c_str(), Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this);
+	if (!my_Handle)
+		throw std::runtime_error("Failed to create window");
+
+	if (Fullscreen)
+		Switch_To_Fullscreen(Mode);
+
+	Create_Context(Mode);
+
+	RECT Rect = {0};
+	GetClientRect(my_Handle, &Rect);
+	//TODO: ...
+}
+
+void Window::Destroy_Window()
+{
+	Destroy_Context();
+	if (my_Handle)
+	{
+		DestroyWindow(my_Handle);
+		my_Handle = 0;
+
+		if (my_Fullscreen)
+			ChangeDisplaySettings(NULL, 0);
+	}
+}
+
+void Window::Create_Context(const Video_Mode &Mode)
+{
+	my_Device_Context = GetDC(my_Handle);
+	if (!my_Device_Context)
+		throw std::runtime_error("Failed to get device context");
+
+	PIXELFORMATDESCRIPTOR Pixel_Descriptor = {0};
+	Pixel_Descriptor.nSize = sizeof(Pixel_Descriptor);
+	Pixel_Descriptor.nVersion = 1;
+	Pixel_Descriptor.iLayerType = PFD_MAIN_PLANE;
+	Pixel_Descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
+	Pixel_Descriptor.iPixelType = PFD_TYPE_RGBA;
+	Pixel_Descriptor.cColorBits = static_cast<BYTE>(Mode.Bits_Per_Pixel);
+	Pixel_Descriptor.cDepthBits = 24;
+	Pixel_Descriptor.cStencilBits = 8;
+	Pixel_Descriptor.cAlphaBits = Mode.Bits_Per_Pixel == 32 ? 8 : 0;
+
+	int Best_Format = ChoosePixelFormat(my_Device_Context, &Pixel_Descriptor);
+	if (0 == Best_Format)
+		throw std::runtime_error("Failed to find suitable pixel format");
+
+	PIXELFORMATDESCRIPTOR Actual_Format = {0};
+	Actual_Format.nSize = sizeof(Actual_Format);
+	Actual_Format.nVersion = 1;
+	DescribePixelFormat(my_Device_Context, Best_Format, sizeof(Actual_Format), &Actual_Format);
+	if (!SetPixelFormat(my_Device_Context, Best_Format, &Actual_Format))
+		throw std::runtime_error("Failed to set device pixel format");
+
+	my_GL_Context = wglCreateContext(my_Device_Context);
+	if (!my_GL_Context)
+		throw std::runtime_error("Failed to create OpenGL context");
+
+	wglMakeCurrent(my_Device_Context, my_GL_Context);
+}
+
+void Window::Destroy_Context()
+{
+	if (my_GL_Context)
+	{
+		wglDeleteContext(my_GL_Context);
+		my_GL_Context = 0;
+	}
+	if (my_Device_Context)
+	{
+		ReleaseDC(my_Handle, my_Device_Context);
+		my_Device_Context = 0;
+	}
+}
+
+void Window::Switch_To_Fullscreen(const Video_Mode &Mode)
+{
+	DEVMODE Device_Mode = {0};
+	Device_Mode.dmSize = sizeof(Device_Mode);
+	Device_Mode.dmPelsWidth = Mode.Width;
+	Device_Mode.dmPelsHeight = Mode.Height;
+	Device_Mode.dmBitsPerPel = Mode.Bits_Per_Pixel;
+	Device_Mode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
+
+	if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettings(&Device_Mode, CDS_FULLSCREEN))
+		throw std::runtime_error("Failed to change to fullscreen mode");
+
+	SetWindowLong(my_Handle, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
+	SetWindowLong(my_Handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
+
+	SetWindowPos(my_Handle, HWND_TOP, 0, 0, Mode.Width, Mode.Height, SWP_FRAMECHANGED);
+}
+
+LRESULT CALLBACK Window::Window_Procedure(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam)
+{
+	switch (Message)
+	{
+	case WM_CREATE:
+		{
+			LONG This = reinterpret_cast<LONG>(reinterpret_cast<CREATESTRUCT *>(lParam)->lpCreateParams);
+			SetWindowLongPtr(Handle, GWLP_USERDATA, This);
+			return 0;
+		}
+		break;
+	case WM_DESTROY:
+		PostQuitMessage(0);
+		return 0;
+		break;
+	default:
+		{
+			Window* Win = reinterpret_cast<Window *>(GetWindowLongPtr(Handle, GWLP_USERDATA));
+			if (Win)
+				return Win->Handle_Message(Handle, Message, wParam, lParam);
+		}
+		break;
+	}
+	return DefWindowProcW(Handle, Message, wParam, lParam);
+}
+
+#define Call_Listener(x)\
+	if (my_Listener) my_Listener->x
+
+LRESULT Window::Handle_Message(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam)
+{
+	switch (Message)
+	{
+	case WM_CLOSE:
+		Call_Listener(On_Close());
+		break;
+	case WM_KEYDOWN:
+		Call_Listener(On_Key_Down(wParam));
+		break;
+	case WM_KEYUP:
+		Call_Listener(On_Key_Up(wParam));
+		break;
+	default:
+		return DefWindowProcW(Handle, Message, wParam, lParam);
+		break;
+	}
+	return 0;
+}
+
+void Window::Show()
+{
+	if (my_Handle)
+		ShowWindow(my_Handle, SW_SHOW);
+}
+
+void Window::Hide()
+{
+	if (my_Handle)
+		ShowWindow(my_Handle, SW_HIDE);
+}
+
+void Window::Update()
+{
+	MSG Message = {0};
+	while (PeekMessageW(&Message, NULL, 0, 0, PM_REMOVE))
+	{
+		TranslateMessage(&Message);
+		DispatchMessageW(&Message);
+	}
+}
+
+void Window::Display()
+{
+	if (my_Device_Context && my_GL_Context)
+		SwapBuffers(my_Device_Context);
+}