changeset 1994:4088cc908c78

auto change color depth to 16 bit
author zipi
date Sun, 03 Nov 2013 11:46:52 +0000
parents a9ca837744d7
children 25e3772e3650
files Game.cpp OSWindow.cpp OSWindow.h
diffstat 3 files changed, 49 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Game.cpp	Sun Nov 03 10:31:01 2013 +0000
+++ b/Game.cpp	Sun Nov 03 11:46:52 2013 +0000
@@ -757,6 +757,7 @@
     WriteWindowsRegistryInt("window X", Rect.left);
     WriteWindowsRegistryInt("window Y", Rect.top);
   }
+  window->Delete();
   WriteWindowsRegistryInt("valAlwaysRun", bAlwaysRun);
   pItemsTable->Release();
   pNPCStats->Release();
--- a/OSWindow.cpp	Sun Nov 03 10:31:01 2013 +0000
+++ b/OSWindow.cpp	Sun Nov 03 11:46:52 2013 +0000
@@ -410,6 +410,15 @@
     return false;
   }
 
+  HDC hDC = GetDC(NULL);
+  int bitsPerPixel = GetDeviceCaps(hDC, BITSPIXEL);
+  int planes = GetDeviceCaps(hDC, PLANES);
+  ReleaseDC(NULL, hDC);
+  if (bitsPerPixel != 16 || planes != 1)
+  {
+	SetColorDepth(16);
+  }
+
   SetWindowedMode(window_width, window_height);
   Show();
 
@@ -789,3 +798,37 @@
 
   return true;
 }
+
+bool OSWindow::SetColorDepth(int bit)
+{
+		dm.dmSize = sizeof(DEVMODE);
+		if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
+		{
+			printf("EnumDisplaySettings failed:%d\n", GetLastError());
+			return false;
+		}
+ 		dm.dmBitsPerPel = bit;
+		dm.dmFields = DM_BITSPERPEL;
+		if (ChangeDisplaySettings(&dm, CDS_TEST) !=DISP_CHANGE_SUCCESSFUL)
+		{
+			printf("\nIllegal graphics mode: %d\n", GetLastError());
+			return false;
+		}
+		if (ChangeDisplaySettings(&dm, 0) == DISP_CHANGE_SUCCESSFUL)
+		{
+			ChangedColorDepth = true;
+		}
+}
+
+void OSWindow::Delete()
+{
+	Deinitialize();
+}
+
+void OSWindow::Deinitialize()
+{
+	if( ChangedColorDepth )
+	{
+		SetColorDepth(32);
+	}
+}
\ No newline at end of file
--- a/OSWindow.h	Sun Nov 03 10:31:01 2013 +0000
+++ b/OSWindow.h	Sun Nov 03 11:46:52 2013 +0000
@@ -6,7 +6,7 @@
 {
   public:
     static OSWindow *Create(const wchar_t *title, int window_width, int window_height);
-
+	void Delete();
 
     void SetFullscreenMode();
     void SetWindowedMode(int new_window_width, int new_window_height);
@@ -38,11 +38,15 @@
 
   protected:
     bool Initialize(const wchar_t *title, int window_width, int window_height);
+	void Deinitialize();
+	bool SetColorDepth(int bit);
     bool WinApiMessageProc(UINT msg, WPARAM wparam, LPARAM lparam, LRESULT *result);
 
     HWND  api_handle;
+	DEVMODE dm;
 
   private:
+	bool ChangedColorDepth;
     static LPARAM __stdcall WinApiMsgRouter(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
 
     HMENU CreateDebugMenuPanel();