DEADSOFTWARE

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