1 (* Copyright (C) DooM 2D:Forever Developers
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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 function SDLMain(): Integer;
25 function GetTimer(): Int64;
26 procedure ResetTimer();
27 function CreateGLWindow(Title
: PChar): Boolean;
28 procedure KillGLWindow();
29 procedure PushExitEvent();
30 function ProcessMessage(): Boolean;
31 procedure ProcessLoading (forceUpdate
: Boolean=false);
32 procedure ReDrawWindow();
33 procedure SwapBuffers();
34 procedure Sleep(ms
: LongWord);
35 function GetDisplayModes(dBPP
: DWORD
; var SelRes
: DWORD
): SArray
;
36 function g_Window_SetDisplay(PreserveGL
: Boolean = False): Boolean;
37 function g_Window_SetSize(W
, H
: Word; FScreen
: Boolean): Boolean;
40 gwin_dump_extensions
: Boolean = false;
41 gwin_has_stencil
: Boolean = false;
42 gwin_k8_enable_light_experiments
: Boolean = false;
43 g_dbg_aimline_on
: Boolean = false;
49 {$IFDEF WINDOWS}Windows
,{$ENDIF}
50 SDL2
, GL
, GLExt
, e_graphics
, e_log
, g_main
,
51 g_console
, SysUtils
, e_input
, g_options
, g_game
,
52 g_basic
, g_textures
, e_sound
, g_sound
, g_menu
, ENet
, g_net
,
53 g_map
, g_gfx
, g_monsters
, g_holmes
, xprofiler
;
59 Time
, Time_Delta
, Time_Old
: Int64;
62 wNeedTimeReset
: Boolean = False;
63 //wWindowCreated: Boolean = False;
64 //wCursorShown: Boolean = False;
65 wMinimized
: Boolean = False;
66 //wNeedFree: Boolean = True;
67 wLoadingProgress
: Boolean = False;
68 wLoadingQuit
: Boolean = False;
69 {wWinPause: Byte = 0;}
71 ticksOverflow
: Int64 = -1;
72 lastTicks
: Uint32
= 0; // to detect overflow
74 curMsButState
: Word = 0;
80 // TODO: move this to a separate file
81 CP1251
: array [0..127] of Word = (
82 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
83 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
84 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
85 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
86 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
87 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
88 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
89 $0440,$0441,$0442,$0443,$0444,$0445,$0446,$0447,$0448,$0449,$044A,$044B,$044C,$044D,$044E,$044F
92 // TODO: make a transition table or something
93 function WCharToCP1251(wc
: Word): Word;
99 if CP1251
[n
] = wc
then begin Result
:= n
; break
end;
100 Result
:= Result
+ 128;
103 function g_Window_SetDisplay(PreserveGL
: Boolean = False): Boolean;
105 mode
, cmode
: TSDL_DisplayMode
;
114 e_WriteLog('Setting display mode...', MSG_NOTIFY
);
116 wFlags
:= SDL_WINDOW_OPENGL
or SDL_WINDOW_RESIZABLE
;
117 if gFullscreen
then wFlags
:= wFlags
or SDL_WINDOW_FULLSCREEN
;
118 if gWinMaximized
then wFlags
:= wFlags
or SDL_WINDOW_MAXIMIZED
;
122 SDL_DestroyWindow(h_Wnd
);
128 mode
.w
:= gScreenWidth
;
129 mode
.h
:= gScreenHeight
;
131 mode
.refresh_rate
:= 0;
132 mode
.driverdata
:= nil;
133 if SDL_GetClosestDisplayMode(0, @mode
, @cmode
) = nil then
136 gScreenHeight
:= 600;
140 gScreenWidth
:= cmode
.w
;
141 gScreenHeight
:= cmode
.h
;
145 h_Wnd
:= SDL_CreateWindow(PChar(wTitle
), gWinRealPosX
, gWinRealPosY
, gScreenWidth
, gScreenHeight
, wFlags
);
146 if h_Wnd
= nil then Exit
;
148 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
149 SDL_ShowCursor(SDL_DISABLE
);
154 procedure ReShowCursor();
156 // TODO: what was this for?
159 function GetDisplayModes(dBPP
: DWORD
; var SelRes
: DWORD
): SArray
;
161 mode
: TSDL_DisplayMode
;
162 res
, i
, k
, n
, pw
, ph
: Integer;
164 SetLength(Result
, 0);
165 {$IFDEF HEADLESS}Exit
;{$ENDIF}
167 n
:= SDL_GetNumDisplayModes(0);
171 res
:= SDL_GetDisplayMode(0, i
, @mode
);
172 if res
< 0 then continue
;
173 if SDL_BITSPERPIXEL(mode
.format
) = gBPP
then continue
;
174 if (mode
.w
= pw
) and (mode
.h
= ph
) then continue
;
175 if (mode
.w
= gScreenWidth
) and (mode
.h
= gScreenHeight
) then
178 SetLength(Result
, k
);
179 Result
[k
-1] := IntToStr(mode
.w
) + 'x' + IntToStr(mode
.h
);
180 pw
:= mode
.w
; ph
:= mode
.h
183 e_WriteLog('SDL: Got ' + IntToStr(k
) + ' resolutions.', MSG_NOTIFY
);
186 procedure Sleep(ms
: LongWord);
191 procedure ChangeWindowSize();
193 gWinSizeX
:= gScreenWidth
;
194 gWinSizeY
:= gScreenHeight
;
195 {$IFDEF HEADLESS}Exit
;{$ENDIF}
196 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
197 g_Game_SetupScreenSize();
199 g_Game_ClearLoading();
200 g_Holmes_VidModeChanged();
203 function g_Window_SetSize(W
, H
: Word; FScreen
: Boolean): Boolean;
208 {$IFDEF HEADLESS}Exit
;{$ENDIF}
211 if (gScreenWidth
<> W
) or (gScreenHeight
<> H
) then
218 if gFullscreen
<> FScreen
then
221 gFullscreen
:= FScreen
;
227 g_Window_SetDisplay(Preserve
);
232 function WindowEventHandler(ev
: TSDL_WindowEvent
): Boolean;
234 wActivate
, wDeactivate
: Boolean;
238 wDeactivate
:= False;
241 SDL_WINDOWEVENT_MOVED
:
243 if not (gFullscreen
or gWinMaximized
) then
245 gWinRealPosX
:= ev
.data1
;
246 gWinRealPosY
:= ev
.data2
;
250 SDL_WINDOWEVENT_MINIMIZED
:
255 if not wMinimized
then
257 e_ResizeWindow(0, 0);
260 if g_debug_WinMsgs
then
262 g_Console_Add('Now minimized');
263 e_WriteLog('[DEBUG] WinMsgs: Now minimized', MSG_NOTIFY
);
269 SDL_WINDOWEVENT_RESIZED
:
273 gScreenWidth
:= ev
.data1
;
274 gScreenHeight
:= ev
.data2
;
277 if g_debug_WinMsgs
then
279 g_Console_Add('Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
));
280 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
), MSG_NOTIFY
);
284 SDL_WINDOWEVENT_EXPOSED
:
287 SDL_WINDOWEVENT_MAXIMIZED
:
293 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
297 if not gWinMaximized
then
299 gWinMaximized
:= True;
300 if g_debug_WinMsgs
then
302 g_Console_Add('Now maximized');
303 e_WriteLog('[DEBUG] WinMsgs: Now maximized', MSG_NOTIFY
);
308 SDL_WINDOWEVENT_RESTORED
:
314 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
318 if gWinMaximized
then
319 gWinMaximized
:= False;
320 if g_debug_WinMsgs
then
322 g_Console_Add('Now restored');
323 e_WriteLog('[DEBUG] WinMsgs: Now restored', MSG_NOTIFY
);
327 SDL_WINDOWEVENT_FOCUS_GAINED
:
332 //e_WriteLog('window gained focus!', MSG_NOTIFY);
333 g_Holmes_WindowFocused();
336 SDL_WINDOWEVENT_FOCUS_LOST
:
342 //e_WriteLog('window lost focus!', MSG_NOTIFY);
343 g_Holmes_WindowBlured();
351 e_WriteLog('deactivating window', MSG_NOTIFY
);
352 e_EnableInput
:= False;
353 e_ClearInputBuffer();
355 if gMuteWhenInactive
then
357 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
358 e_MuteChannels(True);
361 if g_debug_WinMsgs
then
363 g_Console_Add('Now inactive');
364 e_WriteLog('[DEBUG] WinMsgs: Now inactive', MSG_NOTIFY
);
370 else if wActivate
then
372 if not gWinActive
then
374 //e_WriteLog('activating window', MSG_NOTIFY);
375 e_EnableInput
:= True;
377 if gMuteWhenInactive
then
379 //e_WriteLog('activating sounds', MSG_NOTIFY);
380 e_MuteChannels(False);
383 if g_debug_WinMsgs
then
385 g_Console_Add('Now active');
386 e_WriteLog('[DEBUG] WinMsgs: Now active', MSG_NOTIFY
);
394 function EventHandler(ev
: TSDL_Event
): Boolean;
402 function buildBut (b
: Byte): Word;
406 SDL_BUTTON_LEFT
: result
:= result
or THMouseEvent
.Left
;
407 SDL_BUTTON_MIDDLE
: result
:= result
or THMouseEvent
.Middle
;
408 SDL_BUTTON_RIGHT
: result
:= result
or THMouseEvent
.Right
;
412 procedure updateKBState ();
417 kbstate
:= SDL_GetKeyboardState(nil);
418 if (kbstate
[SDL_SCANCODE_LCTRL
] <> 0) or (kbstate
[SDL_SCANCODE_RCTRL
] <> 0) then curKbState
:= curKbState
or THKeyEvent
.ModCtrl
;
419 if (kbstate
[SDL_SCANCODE_LALT
] <> 0) or (kbstate
[SDL_SCANCODE_RALT
] <> 0) then curKbState
:= curKbState
or THKeyEvent
.ModAlt
;
420 if (kbstate
[SDL_SCANCODE_LSHIFT
] <> 0) or (kbstate
[SDL_SCANCODE_RSHIFT
] <> 0) then curKbState
:= curKbState
or THKeyEvent
.ModShift
;
429 Result
:= WindowEventHandler(ev
.window
);
433 if gExit
<> EXIT_QUIT
then
435 if not wLoadingProgress
then
441 wLoadingQuit
:= True;
446 SDL_KEYDOWN
, SDL_KEYUP
:
448 key
:= ev
.key
.keysym
.scancode
;
449 if (g_holmes_enabled
) then
451 if (ev
.type_
= SDL_KEYDOWN
) then kbev
.kind
:= THKeyEvent
.Press
else kbev
.kind
:= THKeyEvent
.Release
;
452 kbev
.scan
:= ev
.key
.keysym
.scancode
;
453 kbev
.sym
:= ev
.key
.keysym
.sym
;
454 kbev
.bstate
:= curMsButState
;
455 kbev
.kstate
:= curKbState
;
456 {$IF not DEFINED(HEADLESS)}
457 if g_Holmes_keyEvent(kbev
) then
459 if (ev
.type_
<> SDL_KEYDOWN
) then e_KeyUpDown(ev
.key
.keysym
.scancode
, false);
464 if (ev
.type_
= SDL_KEYDOWN
) then KeyPress(key
);
465 e_KeyUpDown(ev
.key
.keysym
.scancode
, (ev
.type_
= SDL_KEYDOWN
));
468 {$IF not DEFINED(HEADLESS)}
469 SDL_MOUSEBUTTONDOWN
, SDL_MOUSEBUTTONUP
:
471 msev
.dx
:= ev
.button
.x
-curMsX
;
472 msev
.dy
:= ev
.button
.y
-curMsY
;
473 curMsX
:= ev
.button
.x
;
474 curMsY
:= ev
.button
.y
;
475 if (ev
.type_
= SDL_MOUSEBUTTONDOWN
) then msev
.kind
:= THMouseEvent
.Press
else msev
.kind
:= THMouseEvent
.Release
;
476 msev
.but
:= buildBut(ev
.button
.button
);
479 if (msev
.but
<> 0) then
481 // ev.button.clicks: Byte
482 if (ev
.type_
= SDL_MOUSEBUTTONDOWN
) then curMsButState
:= curMsButState
or msev
.but
else curMsButState
:= curMsButState
and (not msev
.but
);
483 msev
.bstate
:= curMsButState
;
484 msev
.kstate
:= curKbState
;
485 if (g_holmes_enabled
) then g_Holmes_mouseEvent(msev
);
490 if (ev
.wheel
.y
<> 0) then
493 msev
.dy
:= ev
.wheel
.y
;
494 msev
.kind
:= THMouseEvent
.Press
;
495 if (ev
.wheel
.y
< 0) then msev
.but
:= THMouseEvent
.WheelUp
else msev
.but
:= THMouseEvent
.WheelDown
;
498 msev
.bstate
:= curMsButState
;
499 msev
.kstate
:= curKbState
;
500 if (g_holmes_enabled
) then g_Holmes_mouseEvent(msev
);
505 msev
.dx
:= ev
.button
.x
-curMsX
;
506 msev
.dy
:= ev
.button
.y
-curMsY
;
507 curMsX
:= ev
.button
.x
;
508 curMsY
:= ev
.button
.y
;
509 msev
.kind
:= THMouseEvent
.Motion
;
513 msev
.bstate
:= curMsButState
;
514 msev
.kstate
:= curKbState
;
515 if (g_holmes_enabled
) then g_Holmes_mouseEvent(msev
);
521 Utf8ToUnicode(@uc
, PChar(ev
.text.text), 1);
523 if (keychr
> 127) then keychr
:= WCharToCP1251(keychr
);
524 CharPress(Chr(keychr
));
527 // other key presses and joysticks are handled in e_input
531 procedure SwapBuffers();
533 {$IFDEF HEADLESS}Exit
;{$ENDIF}
534 SDL_GL_SwapWindow(h_Wnd
);
537 procedure KillGLWindow();
539 if h_Wnd
<> nil then SDL_DestroyWindow(h_Wnd
);
540 if h_GL
<> nil then SDL_GL_DeleteContext(h_GL
);
543 //wWindowCreated := False;
546 function CreateGLWindow(Title
: PChar): Boolean;
552 gWinSizeX
:= gScreenWidth
;
553 gWinSizeY
:= gScreenHeight
;
556 e_WriteLog('Creating window', MSG_NOTIFY
);
558 if not g_Window_SetDisplay() then
561 e_WriteLog('Window creation error (resolution not supported?)', MSG_FATALERROR
);
566 h_Gl
:= SDL_GL_CreateContext(h_Wnd
);
567 if h_Gl
= nil then Exit
;
569 //wWindowCreated := True;
571 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
578 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
579 function GetTimer(): Int64;
583 QueryPerformanceFrequency(F
);
584 QueryPerformanceCounter(C
);
585 Result
:= Round(C
/F
*1000{000});
588 function GetTimer(): Int64;
593 t
:= SDL_GetTicks() {* 1000}; // TODO: do we really need microseconds here? k8: NOPE!
594 if ticksOverflow
= -1 then
601 if lastTicks
> t
then
603 // overflow, increment overflow ;-)
604 ticksOverflow
:= ticksOverflow
+(Int64($ffffffff)+Int64(1));
605 tt
:= (Int64($ffffffff)+Int64(1))+Int64(t
);
606 t
:= Uint32(tt
-lastTicks
);
610 result
:= ticksOverflow
+Int64(t
);
614 procedure ResetTimer();
616 wNeedTimeReset
:= True;
619 procedure PushExitEvent();
623 ev
.type_
:= SDL_QUITEV
;
629 prevLoadingUpdateTime
: UInt64 = 0;
631 procedure ProcessLoading (forceUpdate
: Boolean=false);
637 FillChar(ev
, SizeOf(ev
), 0);
638 //wNeedFree := False;
639 wLoadingProgress
:= True;
640 while SDL_PollEvent(@ev
) > 0 do
642 if (ev
.type_
= SDL_QUITEV
) then
647 if (ev
.type_
= SDL_QUITEV
) or (gExit
= EXIT_QUIT
) then
649 wLoadingProgress
:= False;
653 if not wMinimized
then
657 prevLoadingUpdateTime
:= curTimeMilli();
661 stt
:= curTimeMilli();
662 if (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= 400) then
664 prevLoadingUpdateTime
:= stt
;
671 if g_Texture_Get('INTER', ID
) then
673 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
677 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
689 if NetMode
= NET_SERVER
then
695 if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then g_Net_Client_UpdateWhileLoading();
697 wLoadingProgress
:= False;
700 function ProcessMessage(): Boolean;
706 FillChar(ev
, SizeOf(ev
), 0);
708 while SDL_PollEvent(@ev
) > 0 do
710 Result
:= EventHandler(ev
);
711 if ev
.type_
= SDL_QUITEV
then exit
;
715 Time_Delta
:= Time
- Time_Old
;
719 if wNeedTimeReset
then
721 Time_Delta
:= 28{(27777 div 1000)};
722 wNeedTimeReset
:= False;
725 g_Map_ProfilersBegin();
726 g_Mons_ProfilersBegin();
728 t
:= Time_Delta
div 28{(27777 div 1000)};
734 if NetMode
= NET_SERVER
then g_Net_Host_Update()
735 else if NetMode
= NET_CLIENT
then g_Net_Client_Update();
741 if NetMode
= NET_SERVER
then g_Net_Host_Update()
742 else if NetMode
= NET_CLIENT
then g_Net_Client_Update();
745 g_Map_ProfilersEnd();
746 g_Mons_ProfilersEnd();
754 if gExit
= EXIT_QUIT
then
760 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ:
763 Time_Old
:= Time
- (Time_Delta
mod 28{(27777 div 1000)});
764 if (not wMinimized
) then
777 procedure ReDrawWindow
;
783 procedure InitOpenGL(VSync
: Boolean);
787 {$IFDEF HEADLESS}Exit
;{$ENDIF}
788 if VSync
then v
:= 1 else v
:= 0;
789 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 2);
790 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
791 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 8);
792 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 8);
793 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 8);
794 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, 16);
795 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
796 if gwin_k8_enable_light_experiments
then
798 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE
, 1); // lights; it is enough to have 1-bit stencil buffer for lighting
800 SDL_GL_SetSwapInterval(v
);
803 function glHasExtension (name
: AnsiString): Boolean;
808 extName
: ShortString;
811 if length(name
) = 0 then exit
;
812 exts
:= glGetString(GL_EXTENSIONS
);
813 if exts
= nil then exit
;
814 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
815 while exts
[0] <> #0 do
817 if gwin_dump_extensions
then
820 while (exts
[i
] <> #0) and (exts
[i
] <> ' ') do Inc(i
);
823 e_WriteLog('FUUUUUUUUUUUUU', MSG_WARNING
);
827 Move(exts
^, extName
[1], i
);
828 extName
[0] := Char(i
);
829 e_WriteLog(Format('EXT: %s', [extName
]), MSG_NOTIFY
);
833 for i
:= 0 to length(name
)-1 do
835 if exts
[i
] = #0 then begin found
:= false; break
; end;
836 if exts
[i
] <> name
[i
+1] then begin found
:= false; break
; end;
838 if found
and ((exts
[length(name
)] = #0) or (exts
[length(name
)] = ' ')) then begin result
:= true; exit
; end;
839 while (exts
[0] <> #0) and (exts
[0] <> ' ') do Inc(exts
);
840 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
844 function SDLMain(): Integer;
851 e_NoGraphics
:= True;
855 while (idx
<= ParamCount
) do
857 arg
:= ParamStr(idx
);
859 if arg
= '--opengl-dump-exts' then gwin_dump_extensions
:= true;
860 if arg
= '--twinkletwinkle' then gwin_k8_enable_light_experiments
:= true;
861 if arg
= '--jah' then g_profile_history_size
:= 100;
862 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
863 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
865 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
866 if arg
= '--profile-coldet' then g_profile_collision
:= true;
867 if arg
= '--profile-los' then g_profile_los
:= true;
869 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
870 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
871 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
872 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
873 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
874 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
876 {$IF DEFINED(D2F_DEBUG)}
877 if arg
= '--aimline' then g_dbg_aimline_on
:= false;
880 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
881 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
883 if (idx
<= ParamCount
) then
885 if not conParseFloat(g_holmes_ui_scale
, ParamStr(idx
)) then g_holmes_ui_scale
:= 1.0;
890 {$IF DEFINED(D2F_DEBUG)}
891 if (arg
= '--game-scale') or (arg
= '-game-scale') then
893 if (idx
<= ParamCount
) then
895 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
902 e_WriteLog('Initializing OpenGL', MSG_NOTIFY
);
905 e_WriteLog('Creating GL window', MSG_NOTIFY
);
906 if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION
]))) then
912 {EnumDisplayModes();}
914 if gwin_k8_enable_light_experiments
then
916 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE
, @ltmp
);
917 e_WriteLog(Format('stencil buffer size: %d', [ltmp
]), MSG_WARNING
);
918 gwin_has_stencil
:= (ltmp
> 0);
922 gwin_has_stencil
:= false;
925 if not glHasExtension('GL_ARB_texture_non_power_of_two') then
927 e_WriteLog('Driver DID''T advertised NPOT textures support', MSG_WARNING
);
928 glLegacyNPOT
:= true;
932 e_WriteLog('Driver advertised NPOT textures support', MSG_NOTIFY
);
933 glLegacyNPOT
:= false;
935 gwin_dump_extensions
:= false;
938 Time_Old
:= GetTimer();
941 if ParamCount
> 0 then
942 g_Game_Process_Params();
945 if (not gGameOn
) and gAskLanguage
then
946 g_Menu_AskLanguage();
948 e_WriteLog('Entering the main loop', MSG_NOTIFY
);
950 while not ProcessMessage() do