3 Quick and Dirty Game Development Framework (QDGDF)
5 Copyright (C) 2001/2011 Angel Ortega <angel@triptico.com>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 http://www.triptico.com
27 #include "qdgdf_video.h"
29 #ifdef CONFOPT_WIN32GDI
38 HINSTANCE hinst
= NULL
;
46 /* keyboard scancodes */
47 static int _scan_codes
[128];
49 /* the double screen */
50 static unsigned char *_double_screen
;
56 static int opengl_flag
= 0;
61 static void draw(HWND hwnd
)
69 hdc
= BeginPaint(hwnd
, &ps
);
71 SetDIBitsToDevice(hdc
, 0, 0,
72 _qdgdfv_screen_x_size
* _qdgdfv_scale
,
73 _qdgdfv_screen_y_size
* _qdgdfv_scale
,
77 _qdgdfv_screen_y_size
* _qdgdfv_scale
,
78 _double_screen
, &bmi
, 0);
85 long STDCALL
WndProc_GDI(HWND hwnd
, UINT msg
, UINT wparam
, LONG lparam
)
86 /* main window Proc */
97 if (isalnum(wparam
)) {
98 _qdgdfv_key_alnum
= 1;
99 _qdgdfv_alnum
= wparam
;
106 k
= (lparam
>> 16) & 0xff;
113 k
= (lparam
>> 16) & 0xff;
116 _qdgdfv_key_alnum
= 0;
134 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
138 static int _qdgdfv_timer(int reset
)
146 /* avoid timer wraps */
157 static void _qdgdfv_set_palette(void)
162 static void _qdgdfv_dump_virtual_screen(void)
164 if (_qdgdfv_scale2x
) {
165 switch (_qdgdfv_scale
) {
167 _qdgdfv_dump4_screen(_qdgdfv_virtual_screen
,
168 (int *) _double_screen
);
172 _qdgdfv_s2x_dump4_screen(_qdgdfv_virtual_screen
,
173 (int *) _double_screen
);
177 _qdgdfv_s3x_dump4_screen(_qdgdfv_virtual_screen
,
178 (int *) _double_screen
);
183 switch (_qdgdfv_scale
) {
185 _qdgdfv_dump4_screen(_qdgdfv_virtual_screen
,
186 (int *) _double_screen
);
190 _qdgdfv_double_dump4_screen(_qdgdfv_virtual_screen
,
191 (int *) _double_screen
);
195 _qdgdfv_triple_dump4_screen(_qdgdfv_virtual_screen
,
196 (int *) _double_screen
);
201 InvalidateRect(hwnd
, NULL
, FALSE
);
205 static void _qdgdfv_input_poll(void)
209 if (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
210 TranslateMessage(&msg
);
211 DispatchMessage(&msg
);
214 _qdgdfv_key_up
= _scan_codes
[0x48];
215 _qdgdfv_key_down
= _scan_codes
[0x50];
216 _qdgdfv_key_left
= _scan_codes
[0x4b];
217 _qdgdfv_key_right
= _scan_codes
[0x4d];
218 _qdgdfv_key_escape
= _scan_codes
[0x01];
219 _qdgdfv_key_space
= _scan_codes
[0x39];
220 _qdgdfv_key_enter
= _scan_codes
[0x1c];
221 _qdgdfv_key_control
= _scan_codes
[0x1d];
222 _qdgdfv_key_pgup
= _scan_codes
[0x49];
223 _qdgdfv_key_pgdn
= _scan_codes
[0x51];
224 _qdgdfv_key_home
= _scan_codes
[0x47];
225 _qdgdfv_key_end
= _scan_codes
[0x4f];
226 /* _qdgdfv_key_control_r = _scan_codes[0x1d];
227 _qdgdfv_key_control_r=_scan_codes[0x36];
228 0x36 is right shift, windows does not differ between left and right control keys, both are 0x1d
230 _qdgdfv_key_shift_l
= _scan_codes
[0x2a];
231 _qdgdfv_key_shift_r
= _scan_codes
[0x36];
233 _qdgdfv_key_f1
= _scan_codes
[0x3b];
234 _qdgdfv_key_f2
= _scan_codes
[0x3c];
235 _qdgdfv_key_f3
= _scan_codes
[0x3d];
236 _qdgdfv_key_f4
= _scan_codes
[0x3e];
237 _qdgdfv_key_f5
= _scan_codes
[0x3f];
238 _qdgdfv_key_f6
= _scan_codes
[0x40];
239 _qdgdfv_key_f7
= _scan_codes
[0x41];
240 _qdgdfv_key_f8
= _scan_codes
[0x42];
241 _qdgdfv_key_f9
= _scan_codes
[0x43];
242 _qdgdfv_key_f10
= _scan_codes
[0x44];
246 static int _qdgdfv_opengl(int onoff
)
250 #ifdef CONFOPT_OPENGL
253 PIXELFORMATDESCRIPTOR pfd
;
256 /* get the device context (DC) */
259 /* set the pixel format for the DC */
260 ZeroMemory(&pfd
, sizeof(pfd
));
261 pfd
.nSize
= sizeof(pfd
);
264 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
;
265 pfd
.iPixelType
= PFD_TYPE_RGBA
;
268 pfd
.iLayerType
= PFD_MAIN_PLANE
;
269 i
= ChoosePixelFormat(hdc
, &pfd
);
270 SetPixelFormat(hdc
, i
, &pfd
);
272 /* create and enable the render context (RC) */
273 hrc
= wglCreateContext(hdc
);
274 wglMakeCurrent(hdc
, hrc
);
277 wglMakeCurrent(NULL
, NULL
);
278 wglDeleteContext(hrc
);
279 ReleaseDC(hwnd
, hdc
);
291 static int _qdgdfv_startup(void)
298 if (_qdgdfv_full_screen
== -1)
299 _qdgdfv_full_screen
= 0;
301 /* reject full screen mode */
302 if (_qdgdfv_full_screen
== 1)
305 if (_qdgdfv_scale
> 3)
308 _qdgdfv_pixel_size
= 4;
310 _qdgdfv_red_mask
= 0xff000000;
311 _qdgdfv_red_shift
= 8;
313 _qdgdfv_green_mask
= 0xff000000;
314 _qdgdfv_green_shift
= 16;
316 _qdgdfv_blue_mask
= 0xff000000;
317 _qdgdfv_blue_shift
= 24;
319 hinst
= (HINSTANCE
) _qdgdfv_additional_int_info
;
321 /* register the window */
322 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
323 wc
.lpfnWndProc
= WndProc_GDI
;
326 wc
.hInstance
= hinst
;
328 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
329 wc
.hbrBackground
= NULL
;
330 wc
.lpszMenuName
= NULL
;
331 wc
.lpszClassName
= L
"qdgdf_gdi";
333 if (!RegisterClassW(&wc
)) {
334 qdgdfv_logger("qdgdfv_startup", "RegisterClass error");
338 /* create the window */
339 hwnd
= CreateWindowW(L
"qdgdf_gdi", L
"",
340 WS_OVERLAPPED
| WS_CLIPCHILDREN
,
341 CW_USEDEFAULT
, CW_USEDEFAULT
,
342 CW_USEDEFAULT
, CW_USEDEFAULT
,
343 NULL
, NULL
, hinst
, NULL
);
346 qdgdfv_logger("qdgdfv_startup", "WIN32 GDI CreateWindow error");
350 _qdgdfv_virtual_screen
= (unsigned char *)
351 qdgdfv_malloc(_qdgdfv_screen_x_size
* _qdgdfv_screen_y_size
);
353 _double_screen
= (unsigned char *)
354 qdgdfv_malloc(_qdgdfv_screen_x_size
* _qdgdfv_screen_y_size
*
355 _qdgdfv_scale
* _qdgdfv_scale
* _qdgdfv_pixel_size
);
357 GetClientRect(hwnd
, &cr
);
358 GetWindowRect(hwnd
, &wr
);
363 _qdgdfv_screen_x_size
* _qdgdfv_scale
+ (wr
.right
-
366 _qdgdfv_screen_y_size
* _qdgdfv_scale
+ (wr
.bottom
-
370 qdgdfv_clear_virtual_screen();
372 ShowWindow(hwnd
, SW_SHOW
);
376 /* fill the bitmap information */
377 memset(&bmi
, '\0', sizeof(bmi
));
380 h
->biSize
= sizeof(BITMAPINFOHEADER
);
381 h
->biWidth
= _qdgdfv_screen_x_size
* _qdgdfv_scale
;
382 h
->biHeight
= -_qdgdfv_screen_y_size
* _qdgdfv_scale
;
385 h
->biCompression
= BI_RGB
;
388 h
->biClrImportant
= 0;
390 SetWindowText(hwnd
, _qdgdfv_window_title
);
392 qdgdfv_logger("qdgdfv_startup", "Win32 GDI driver startup");
398 static void _qdgdfv_shutdown(void)
400 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
402 qdgdfv_logger("qdgdfv_startup", "Win32 GDI driver shutdown");
406 /** driver information **/
408 static struct _qdgdfv_driver drv
= {
411 _qdgdfv_dump_virtual_screen
,
420 struct _qdgdfv_driver
*win32gdi_drv_detect(void)
421 /* detection function */
423 if (_qdgdfv_startup())
429 #endif /* CONFOPT_WIN32GDI */