DEADSOFTWARE

Game: Use proper syntax of sets for game options instead of raw bitwise operations
[d2df-sdl.git] / src / game / sdl2 / g_system.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_system;
18 interface
20 uses Utils;
22 (* --- Utils --- *)
23 function sys_GetTicks (): Int64;
24 procedure sys_Delay (ms: Integer);
26 (* --- Graphics --- *)
27 function sys_GetDisplayModes (bpp: Integer): SSArray;
28 function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen, maximized: Boolean): Boolean;
29 procedure sys_EnableVSync (yes: Boolean);
30 procedure sys_Repaint;
32 (* --- Input --- *)
33 function sys_HandleInput (): Boolean;
34 procedure sys_RequestQuit;
36 (* --- Init --- *)
37 procedure sys_Init;
38 procedure sys_Final;
40 implementation
42 uses
43 SysUtils, SDL2, Math, ctypes,
44 e_log, e_graphics, e_input, e_sound,
45 {$INCLUDE ../nogl/noGLuses.inc}
46 {$IFDEF ENABLE_HOLMES}
47 g_holmes, sdlcarcass, fui_ctls,
48 {$ENDIF}
49 g_touch, g_options, g_window, g_console, g_game, g_menu, g_gui, g_main, g_basic;
51 const
52 GameTitle = 'Doom 2D: Forever (SDL 2, %s)';
54 var
55 window: PSDL_Window;
56 context: TSDL_GLContext;
57 display, wx, wy: Integer;
58 wc: Boolean;
59 JoystickHandle: array [0..e_MaxJoys - 1] of PSDL_Joystick;
60 JoystickHatState: array [0..e_MaxJoys - 1, 0..e_MaxJoyHats - 1, HAT_LEFT..HAT_DOWN] of Boolean;
61 JoystickZeroAxes: array [0..e_MaxJoys - 1, 0..e_MaxJoyAxes - 1] of Integer;
63 (* --------- Utils --------- *)
65 function sys_GetTicks (): Int64;
66 begin
67 result := SDL_GetTicks()
68 end;
70 procedure sys_Delay (ms: Integer);
71 begin
72 SDL_Delay(ms)
73 end;
75 (* --------- Graphics --------- *)
77 function LoadGL: Boolean;
78 var ltmp: Integer;
79 begin
80 result := true;
81 {$IFDEF NOGL_INIT}
82 nogl_Init;
83 if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then
84 begin
85 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
86 glRenderToFBO := false;
87 end;
88 {$ELSE}
89 if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then
90 begin
91 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
92 glRenderToFBO := false;
93 end;
94 {$ENDIF}
95 if SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, @ltmp) = 0 then
96 begin
97 e_LogWritefln('stencil buffer size: %s', [ltmp]);
98 gwin_has_stencil := (ltmp > 0);
99 end;
100 end;
102 procedure FreeGL;
103 begin
104 {$IFDEF NOGL_INIT}
105 nogl_Quit();
106 {$ENDIF}
107 end;
109 procedure UpdateSize (w, h: Integer);
110 begin
111 gWinSizeX := w;
112 gWinSizeY := h;
113 gRC_Width := w;
114 gRC_Height := h;
115 if glRenderToFBO then
116 begin
117 // store real window size in gWinSize, downscale resolution now
118 w := round(w / r_pixel_scale);
119 h := round(h / r_pixel_scale);
120 if not e_ResizeFramebuffer(w, h) then
121 begin
122 e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
123 glRenderToFBO := False;
124 w := gWinSizeX;
125 h := gWinSizeY;
126 end;
127 end;
128 gScreenWidth := w;
129 gScreenHeight := h;
130 {$IFDEF ENABLE_HOLMES}
131 fuiScrWdt := w;
132 fuiScrHgt := h;
133 {$ENDIF}
134 e_ResizeWindow(w, h);
135 e_InitGL;
136 g_Game_SetupScreenSize;
137 {$IFNDEF ANDROID}
138 (* This will fix menu reset on keyboard showing *)
139 g_Menu_Reset;
140 {$ENDIF}
141 g_Game_ClearLoading;
142 {$IFDEF ENABLE_HOLMES}
143 if assigned(oglInitCB) then oglInitCB;
144 {$ENDIF}
145 end;
147 function GetTitle (): AnsiString;
148 var info: AnsiString;
149 begin
150 info := g_GetBuildHash(false);
151 if info = 'custom build' then
152 info := info + ' by ' + g_GetBuilderName() + ' ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME;
153 result := Format(GameTitle, [info]);
154 end;
156 function InitWindow (w, h, bpp: Integer; fullScreen, maximized: Boolean): Boolean;
157 var flags: UInt32; x, y: cint; title: AnsiString;
158 begin
159 // note: on window close make: if assigned(oglDeinitCB) then oglDeinitCB;
160 e_LogWritefln('InitWindow %s %s %s %s', [w, h, bpp, fullScreen]);
161 result := false;
162 if window = nil then
163 begin
164 {$IFDEF USE_GLES1}
165 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
166 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
167 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
168 {$ELSE}
169 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
170 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
171 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
172 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
173 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
174 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
175 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
176 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
177 {$ENDIF}
178 flags := SDL_WINDOW_OPENGL or SDL_WINDOW_RESIZABLE;
179 if fullScreen then flags := flags or SDL_WINDOW_FULLSCREEN;
180 if maximized then flags := flags or SDL_WINDOW_MAXIMIZED;
181 if wc then
182 begin
183 x := SDL_WINDOWPOS_CENTERED;
184 y := SDL_WINDOWPOS_CENTERED
185 end
186 else
187 begin
188 x := wx;
189 y := wy
190 end;
191 title := GetTitle();
192 window := SDL_CreateWindow(PChar(title), x, y, w, h, flags);
193 if window <> nil then
194 begin
195 context := SDL_GL_CreateContext(window);
196 if context <> nil then
197 begin
198 if not LoadGL then
199 begin
200 e_LogWriteln('GL: unable to load OpenGL functions', TMsgType.Fatal);
201 SDL_GL_DeleteContext(context); context := nil;
202 exit;
203 end;
204 if (fullscreen = false) and (maximized = false) and (wc = false) then
205 begin
206 SDL_GetWindowPosition(window, @x, @y);
207 wx := x; wy := y
208 end;
209 gFullScreen := fullscreen;
210 gWinMaximized := maximized;
211 gRC_FullScreen := fullscreen;
212 gRC_Maximized := maximized;
213 UpdateSize(w, h);
214 result := true
215 end
216 else
217 begin
218 // SDL_DestroyWindow(window);
219 e_LogWritefln('SDL: unable to create OpenGL context: %s', [SDL_GetError])
220 end
221 end
222 else
223 begin
224 e_LogWritefln('SDL: unable to create window: %s', [SDL_GetError])
225 end
226 end
227 else
228 begin
229 if fullScreen then flags := SDL_WINDOW_FULLSCREEN else flags := 0;
230 SDL_SetWindowFullscreen(window, flags);
231 SDL_SetWindowSize(window, w, h);
232 if maximized then SDL_MaximizeWindow(window);
233 // always reset to center when changing fullscreen->windowed for safety purposes
234 if wc or (gFullscreen and not fullscreen) or (gWinMaximized and not maximized) then
235 begin
236 x := SDL_WINDOWPOS_CENTERED;
237 y := SDL_WINDOWPOS_CENTERED
238 end
239 else
240 begin
241 x := wx;
242 y := wy
243 end;
244 SDL_SetWindowPosition(window, x, y);
245 if (fullscreen = false) and (maximized = false) and (wc = false) then
246 begin
247 SDL_GetWindowPosition(window, @x, @y);
248 wx := x; wy := y
249 end;
250 gFullScreen := fullscreen;
251 gWinMaximized := maximized;
252 gRC_FullScreen := fullscreen;
253 gRC_Maximized := maximized;
254 UpdateSize(w, h);
255 result := true
256 end
257 end;
259 procedure sys_Repaint;
260 begin
261 SDL_GL_SwapWindow(window)
262 end;
264 procedure sys_EnableVSync (yes: Boolean);
265 begin
266 if yes then
267 SDL_GL_SetSwapInterval(1)
268 else
269 SDL_GL_SetSwapInterval(0)
270 end;
272 function sys_GetDisplayModes (bpp: Integer): SSArray;
273 var i, count, num, pw, ph: Integer; m: TSDL_DisplayMode;
274 begin
275 result := nil;
276 num := SDL_GetNumDisplayModes(display);
277 if num < 0 then
278 e_LogWritefln('SDL: unable to get numer of available display modes: %s', [SDL_GetError]);
279 if num > 0 then
280 begin
281 e_LogWritefln('Video modes for display %s:', [display]);
282 SetLength(result, num);
283 i := 0; count := 0; pw := 0; ph := 0;
284 while i < num do
285 begin
286 SDL_GetDisplayMode(display, i, @m);
287 if ((pw <> m.w) or (ph <> m.h)) then
288 begin
289 e_LogWritefln('* %sx%sx%s@%s', [m.w, m.h, SDL_BITSPERPIXEL(m.format), m.refresh_rate]);
290 pw := m.w; ph := m.h;
291 result[count] := IntToStr(m.w) + 'x' + IntToStr(m.h);
292 Inc(count);
293 end
294 else
295 begin
296 e_LogWritefln('- %sx%sx%s@%s', [m.w, m.h, SDL_BITSPERPIXEL(m.format), m.refresh_rate]);
297 end;
298 Inc(i)
299 end;
300 SetLength(result, count)
301 end
302 end;
304 function sys_SetDisplayMode (w, h, bpp: Integer; fullScreen, maximized: Boolean): Boolean;
305 begin
306 result := InitWindow(w, h, bpp, fullScreen, maximized)
307 end;
309 (* --------- Joystick --------- *)
311 procedure HandleJoyButton (var ev: TSDL_JoyButtonEvent);
312 var down: Boolean; key: Integer;
313 begin
314 if (ev.which < e_MaxJoys) and (ev.button < e_MaxJoyBtns) then
315 begin
316 key := e_JoyButtonToKey(ev.which, ev.button);
317 down := ev.type_ = SDL_JOYBUTTONDOWN;
318 if g_dbg_input then
319 e_LogWritefln('Input Debug: jbutton, joy=%s, button=%s, keycode=%s, press=%s', [ev.which, ev.button, key, down]);
320 e_KeyUpDown(key, down);
321 g_Console_ProcessBind(key, down)
322 end
323 else
324 begin
325 if g_dbg_input then
326 begin
327 down := ev.type_ = SDL_JOYBUTTONDOWN;
328 e_LogWritefln('Input Debug: NOT IN RANGE! jbutton, joy=%s, button=%s, press=%s', [ev.which, ev.button, down])
329 end
330 end
331 end;
333 procedure HandleJoyAxis (var ev: TSDL_JoyAxisEvent);
334 var key, minuskey: Integer;
335 begin
336 if (ev.which < e_MaxJoys) and (ev.axis < e_MaxJoyAxes) then
337 begin
338 key := e_JoyAxisToKey(ev.which, ev.axis, AX_PLUS);
339 minuskey := e_JoyAxisToKey(ev.which, ev.axis, AX_MINUS);
341 if g_dbg_input then
342 e_LogWritefln('Input Debug: jaxis, joy=%s, axis=%s, value=%s, zeroaxes=%s, deadzone=%s', [ev.which, ev.axis, ev.value, JoystickZeroAxes[ev.which, ev.axis], e_JoystickDeadzones[ev.which]]);
344 if ev.value < JoystickZeroAxes[ev.which, ev.axis] - e_JoystickDeadzones[ev.which] then
345 begin
346 if (e_KeyPressed(key)) then
347 begin
348 e_KeyUpDown(key, False);
349 g_Console_ProcessBind(key, False)
350 end;
351 e_KeyUpDown(minuskey, True);
352 g_Console_ProcessBind(minuskey, True)
353 end
354 else if ev.value > JoystickZeroAxes[ev.which, ev.axis] + e_JoystickDeadzones[ev.which] then
355 begin
356 if (e_KeyPressed(minuskey)) then
357 begin
358 e_KeyUpDown(minuskey, False);
359 g_Console_ProcessBind(minuskey, False)
360 end;
361 e_KeyUpDown(key, True);
362 g_Console_ProcessBind(key, True)
363 end
364 else
365 begin
366 if (e_KeyPressed(minuskey)) then
367 begin
368 e_KeyUpDown(minuskey, False);
369 g_Console_ProcessBind(minuskey, False)
370 end;
371 if (e_KeyPressed(key)) then
372 begin
373 e_KeyUpDown(key, False);
374 g_Console_ProcessBind(key, False)
375 end
376 end
377 end
378 else
379 begin
380 if g_dbg_input then
381 e_LogWritefln('Input Debug: NOT IN RANGE! jaxis, joy=%s, axis=%s, value=%s, zeroaxes=%s, deadzone=%s', [ev.which, ev.axis, ev.value, JoystickZeroAxes[ev.which, ev.axis], e_JoystickDeadzones[ev.which]])
382 end
383 end;
385 procedure HandleJoyHat (var ev: TSDL_JoyHatEvent);
386 var
387 down: Boolean;
388 i, key: Integer;
389 hat: array [HAT_LEFT..HAT_DOWN] of Boolean;
390 begin
391 if (ev.which < e_MaxJoys) and (ev.hat < e_MaxJoyHats) then
392 begin
393 if g_dbg_input then
394 e_LogWritefln('Input Debug: jhat, joy=%s, hat=%s, value=%s', [ev.which, ev.hat, ev.value]);
395 hat[HAT_UP] := LongBool(ev.value and SDL_HAT_UP);
396 hat[HAT_DOWN] := LongBool(ev.value and SDL_HAT_DOWN);
397 hat[HAT_LEFT] := LongBool(ev.value and SDL_HAT_LEFT);
398 hat[HAT_RIGHT] := LongBool(ev.value and SDL_HAT_RIGHT);
399 for i := HAT_LEFT to HAT_DOWN do
400 begin
401 if JoystickHatState[ev.which, ev.hat, i] <> hat[i] then
402 begin
403 down := hat[i];
404 key := e_JoyHatToKey(ev.which, ev.hat, i);
405 e_KeyUpDown(key, down);
406 g_Console_ProcessBind(key, down)
407 end
408 end;
409 JoystickHatState[ev.which, ev.hat] := hat
410 end
411 else
412 begin
413 if g_dbg_input then
414 e_LogWritefln('Input Debug: NOT IN RANGE! jhat, joy=%s, hat=%s, value=%s', [ev.which, ev.hat, ev.value])
415 end
416 end;
418 procedure HandleJoyAdd (var ev: TSDL_JoyDeviceEvent);
419 var i: Integer;
420 begin
421 if (ev.which < e_MaxJoys) then
422 begin
423 JoystickHandle[ev.which] := SDL_JoystickOpen(ev.which);
424 if JoystickHandle[ev.which] <> nil then
425 begin
426 e_LogWritefln('Added Joystick %s', [ev.which]);
427 e_JoystickAvailable[ev.which] := True;
428 for i := 0 to Min(SDL_JoystickNumAxes(JoystickHandle[ev.which]), e_MaxJoyAxes) - 1 do
429 JoystickZeroAxes[ev.which, i] := SDL_JoystickGetAxis(JoystickHandle[ev.which], i)
430 end
431 else
432 begin
433 e_LogWritefln('Warning! Failed to open Joystick %s', [ev.which])
434 end
435 end
436 else
437 begin
438 e_LogWritefln('Warning! Added Joystick %s, but we support only <= %s', [ev.which, e_MaxJoys])
439 end
440 end;
442 procedure HandleJoyRemove (var ev: TSDL_JoyDeviceEvent);
443 begin
444 e_LogWritefln('Removed Joystick %s', [ev.which]);
445 if (ev.which < e_MaxJoys) then
446 begin
447 e_JoystickAvailable[ev.which] := False;
448 if JoystickHandle[ev.which] <> nil then
449 SDL_JoystickClose(JoystickHandle[ev.which]);
450 JoystickHandle[ev.which] := nil
451 end
452 end;
454 (* --------- Input --------- *)
456 function HandleWindow (var ev: TSDL_WindowEvent): Boolean;
457 begin
458 result := false;
459 if g_dbg_input then
460 e_LogWritefln('Window Event: event = %s, data1 = %s, data2 = %s', [ev.event, ev.data1, ev.data2]);
461 case ev.event of
462 SDL_WINDOWEVENT_RESIZED: UpdateSize(ev.data1, ev.data2);
463 SDL_WINDOWEVENT_EXPOSED: sys_Repaint;
464 SDL_WINDOWEVENT_CLOSE: result := true;
465 SDL_WINDOWEVENT_MOVED:
466 begin
467 wx := ev.data1;
468 wy := ev.data2
469 end;
470 SDL_WINDOWEVENT_FOCUS_LOST, SDL_WINDOWEVENT_MINIMIZED:
471 begin
472 e_UnpressAllKeys;
473 if gMuteWhenInactive then
474 e_MuteChannels(true);
475 {$IFDEF ENABLE_HOLMES}
476 if assigned(winBlurCB) then winBlurCB;
477 {$ENDIF}
478 end;
479 SDL_WINDOWEVENT_FOCUS_GAINED, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_RESTORED:
480 begin
481 if ev.event = SDL_WINDOWEVENT_MAXIMIZED then
482 begin
483 gWinMaximized := true;
484 gRC_Maximized := true
485 end
486 else if ev.event = SDL_WINDOWEVENT_RESTORED then
487 begin
488 gWinMaximized := false;
489 gRC_Maximized := false
490 end;
491 e_MuteChannels(false);
492 {$IFDEF ENABLE_HOLMES}
493 if assigned(winFocusCB) then winFocusCB;
494 {$ENDIF}
495 end;
496 end
497 end;
499 procedure HandleKeyboard (var ev: TSDL_KeyboardEvent);
500 var down: Boolean; key: Integer;
501 begin
502 key := ev.keysym.scancode;
503 down := (ev.type_ = SDL_KEYDOWN);
504 if key = SDL_SCANCODE_AC_BACK then
505 key := SDL_SCANCODE_ESCAPE;
506 {$IFDEF ENABLE_HOLMES}
507 if fuiOnSDLEvent(PSDL_Event(@ev)^) then
508 begin
509 // event eaten, but...
510 if not down then e_KeyUpDown(key, false);
511 exit;
512 end;
513 {$ENDIF}
514 if ev._repeat = 0 then
515 begin
516 if g_dbg_input then
517 e_LogWritefln('Input Debug: keysym, press=%s, scancode=%s', [down, key]);
518 e_KeyUpDown(key, down);
519 g_Console_ProcessBind(key, down);
520 end
521 else
522 begin
523 if g_dbg_input then
524 e_LogWritefln('Input Debug: keyrep, scancode=%s', [key]);
525 g_Console_ProcessBindRepeat(key);
526 end
527 end;
529 procedure HandleTextInput (var ev: TSDL_TextInputEvent);
530 var ch: UnicodeChar; sch: AnsiChar;
531 begin
532 Utf8ToUnicode(@ch, PChar(ev.text), 1);
533 sch := AnsiChar(wchar2win(ch));
534 if g_dbg_input then
535 e_LogWritefln('Input Debug: text, text="%s", ch = %s, sch = %s', [ev.text, Ord(ch), Ord(sch)]);
536 if IsValid1251(Word(ch)) and IsPrintable1251(ch) then
537 CharPress(sch);
538 end;
540 function sys_HandleInput (): Boolean;
541 var ev: TSDL_Event;
542 begin
543 result := false;
544 ZeroMemory(@ev, sizeof(ev));
545 while SDL_PollEvent(@ev) <> 0 do
546 begin
547 case ev.type_ of
548 SDL_QUITEV: result := true;
549 SDL_WINDOWEVENT: result := HandleWindow(ev.window);
550 SDL_KEYUP, SDL_KEYDOWN: HandleKeyboard(ev.key);
551 SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP: HandleJoyButton(ev.jbutton);
552 SDL_JOYAXISMOTION: HandleJoyAxis(ev.jaxis);
553 SDL_JOYHATMOTION: HandleJoyHat(ev.jhat);
554 SDL_JOYDEVICEADDED: HandleJoyAdd(ev.jdevice);
555 SDL_JOYDEVICEREMOVED: HandleJoyRemove(ev.jdevice);
556 SDL_TEXTINPUT: HandleTextInput(ev.text);
557 SDL_FINGERMOTION, SDL_FINGERDOWN, SDL_FINGERUP: g_Touch_HandleEvent(ev.tfinger);
558 {$IFDEF ENABLE_HOLMES}
559 SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_MOUSEWHEEL, SDL_MOUSEMOTION: fuiOnSDLEvent(ev);
560 {$ENDIF}
561 end
562 end
563 end;
565 procedure sys_RequestQuit;
566 var ev: TSDL_Event;
567 begin
568 ev.type_ := SDL_QUITEV;
569 SDL_PushEvent(@ev)
570 end;
572 (* --------- Init --------- *)
574 procedure sys_Init;
575 var flags: UInt32;
576 begin
577 e_WriteLog('Init SDL2', TMsgType.Notify);
578 {$IFDEF HEADLESS}
579 {$IFDEF USE_SDLMIXER}
580 flags := SDL_INIT_TIMER or SDL_INIT_AUDIO or $00004000;
581 {$ELSE}
582 flags := SDL_INIT_TIMER or $00004000;
583 {$ENDIF}
584 {$ELSE}
585 flags := SDL_INIT_TIMER or SDL_INIT_VIDEO;
586 {$ENDIF}
587 SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, '0');
588 if SDL_Init(flags) <> 0 then
589 raise Exception.Create('SDL: Init failed: ' + SDL_GetError);
590 {$IFNDEF HEADLESS}
591 if SDL_InitSubSystem(SDL_INIT_JOYSTICK) <> 0 then
592 e_LogWritefln('SDL: Init subsystem failed: %s', [SDL_GetError()]);
593 {$ENDIF}
594 SDL_ShowCursor(SDL_DISABLE);
595 end;
597 procedure sys_Final;
598 begin
599 e_WriteLog('Releasing SDL2', TMsgType.Notify);
600 if context <> nil then
601 begin
602 FreeGL;
603 SDL_GL_DeleteContext(context);
604 context := nil;
605 end;
606 if window <> nil then
607 begin
608 SDL_DestroyWindow(window);
609 window := nil;
610 end;
611 SDL_Quit
612 end;
614 initialization
615 conRegVar('sdl2_display_index', @display, 'use display index as base', '');
616 conRegVar('sdl2_window_x', @wx, 'window position x', '');
617 conRegVar('sdl2_window_y', @wy, 'window position y', '');
618 conRegVar('sdl2_window_center', @wc, 'force window creation at center', '');
619 display := 0;
620 wx := SDL_WINDOWPOS_CENTERED;
621 wy := SDL_WINDOWPOS_CENTERED;
622 wc := false
623 end.