comparison src/video/win32/SDL_win32video.c @ 1725:98a3207ddde8 SDL-1.3

Implemented Win32 video mode support
author Sam Lantinga <slouken@libsdl.org>
date Fri, 07 Jul 2006 08:05:39 +0000
parents 6c63fc2bd986
children e70477157db9
comparison
equal deleted inserted replaced
1724:6c63fc2bd986 1725:98a3207ddde8
30 #include "SDL_win32video.h" 30 #include "SDL_win32video.h"
31 #include "SDL_dibrender.h" 31 #include "SDL_dibrender.h"
32 32
33 /* Initialization/Query functions */ 33 /* Initialization/Query functions */
34 static int WIN_VideoInit(_THIS); 34 static int WIN_VideoInit(_THIS);
35 static int WIN_SetDisplayMode(_THIS, const SDL_DisplayMode * mode);
36 static void WIN_VideoQuit(_THIS); 35 static void WIN_VideoQuit(_THIS);
37 36
38 /* WIN32 driver bootstrap functions */ 37 /* WIN32 driver bootstrap functions */
39 38
40 static int 39 static int
106 105
107 106
108 int 107 int
109 WIN_VideoInit(_THIS) 108 WIN_VideoInit(_THIS)
110 { 109 {
111 int bmi_size; 110 WIN_InitModes(_this);
112 LPBITMAPINFO bmi;
113 SDL_DisplayMode mode;
114
115 /* Find out the desktop mode */
116 mode.format = SDL_PixelFormat_Unknown;
117 mode.w = GetSystemMetrics(SM_CXSCREEN);
118 mode.h = GetSystemMetrics(SM_CYSCREEN);
119 mode.refresh_rate = 0;
120
121 bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
122 bmi = (LPBITMAPINFO) SDL_malloc(bmi_size);
123 if (bmi) {
124 HDC hdc;
125 HBITMAP hbm;
126
127 SDL_memset(bmi, 0, bmi_size);
128 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
129 hdc = GetDC(NULL);
130 hbm = CreateCompatibleBitmap(hdc, 1, 1);
131 GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
132 GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
133 DeleteObject(hbm);
134 ReleaseDC(NULL, hdc);
135 if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
136 switch (*(Uint32 *) bmi->bmiColors) {
137 case 0x00FF0000:
138 mode.format = SDL_PixelFormat_RGB888;
139 break;
140 case 0x000000FF:
141 mode.format = SDL_PixelFormat_BGR888;
142 break;
143 case 0xF800:
144 mode.format = SDL_PixelFormat_RGB565;
145 break;
146 case 0x7C00:
147 mode.format = SDL_PixelFormat_RGB555;
148 break;
149 }
150 } else if (bmi->bmiHeader.biBitCount == 8) {
151 mode.format = SDL_PixelFormat_Index8;
152 }
153 }
154 SDL_AddBasicVideoDisplay(&mode);
155 SDL_AddRenderDriver(0, &SDL_DIB_RenderDriver); 111 SDL_AddRenderDriver(0, &SDL_DIB_RenderDriver);
156 112
157 SDL_zero(mode); 113 WIN_InitKeyboard(_this);
158 SDL_AddDisplayMode(0, &mode); 114 WIN_InitMouse(_this);
159 115
160 WIN_AddKeyboard(_this);
161 WIN_AddMouse(_this);
162
163 /* We're done! */
164 return 0;
165 }
166
167 static int
168 WIN_SetDisplayMode(_THIS, const SDL_DisplayMode * mode)
169 {
170 SDL_CurrentDisplay.current_mode = *mode;
171 return 0; 116 return 0;
172 } 117 }
173 118
174 void 119 void
175 WIN_VideoQuit(_THIS) 120 WIN_VideoQuit(_THIS)
176 { 121 {
177 WIN_DelKeyboard(_this); 122 WIN_QuitModes(_this);
178 WIN_DelMouse(_this); 123 WIN_QuitKeyboard(_this);
124 WIN_QuitMouse(_this);
179 } 125 }
180 126
181 /* vim: set ts=4 sw=4 expandtab: */ 127 /* vim: set ts=4 sw=4 expandtab: */