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 procedure PushExitEvent ();
28 function ProcessMessage (): Boolean;
29 procedure ReDrawWindow ();
30 procedure SwapBuffers ();
31 procedure Sleep (ms
: LongWord);
32 function GetDisplayModes (dbpp
: LongWord; var selres
: LongWord): SSArray
;
33 function g_Window_SetDisplay (preserveGL
: Boolean=false): Boolean;
34 function g_Window_SetSize (w
, h
: Word; fullscreen
: Boolean): Boolean;
35 procedure g_SetVSync (vsync
: Boolean);
37 procedure ProcessLoading (forceUpdate
: Boolean=false);
39 // returns `true` if quit event was received
40 function g_ProcessMessages (): Boolean;
44 gwin_dump_extensions
: Boolean = false;
45 gwin_has_stencil
: Boolean = false;
46 gwin_k8_enable_light_experiments
: Boolean = false;
47 g_dbg_aimline_on
: Boolean = false;
53 {$IFDEF WINDOWS}Windows
,{$ENDIF}
54 SysUtils
, Classes
, MAPDEF
,
55 SDL2
, GL
, GLExt
, e_graphics
, e_log
, e_texture
, g_main
,
56 g_console
, e_input
, g_options
, g_game
,
57 g_basic
, g_textures
, e_sound
, g_sound
, g_menu
, ENet
, g_net
,
58 g_map
, g_gfx
, g_monsters
, g_holmes
, xprofiler
,
63 ProgressUpdateMSecs
= 1;//100;
66 h_Wnd
: PSDL_Window
= nil;
67 h_GL
: TSDL_GLContext
= nil;
68 Time
, Time_Delta
, Time_Old
: Int64;
70 {$IF not DEFINED(HEADLESS)}
72 wasFullscreen
: Boolean = true; // so we need to recreate the window
74 wNeedTimeReset
: Boolean = false;
75 wMinimized
: Boolean = false;
76 wMaximized
: Boolean = false;
77 wLoadingProgress
: Boolean = false;
78 wLoadingQuit
: Boolean = false;
80 ticksOverflow
: Int64 = -1;
81 lastTicks
: Uint32
= 0; // to detect overflow
85 procedure KillGLWindow (preserveGL
: Boolean);
87 if (h_GL
<> nil) and (not preserveGL
) then begin if (assigned(oglDeinitCB
)) then oglDeinitCB(); end;
88 if (h_Wnd
<> nil) then SDL_DestroyWindow(h_Wnd
);
89 if (h_GL
<> nil) and (not preserveGL
) then SDL_GL_DeleteContext(h_GL
);
91 if (not preserveGL
) then h_GL
:= nil;
95 function g_Window_SetDisplay (preserveGL
: Boolean = false): Boolean;
96 {$IF not DEFINED(HEADLESS)}
98 mode
, cmode
: TSDL_DisplayMode
;
103 {$IF not DEFINED(HEADLESS)}
106 e_WriteLog('Setting display mode...', TMsgType
.Notify
);
108 wFlags
:= SDL_WINDOW_OPENGL
{or SDL_WINDOW_RESIZABLE};
109 if gFullscreen
then wFlags
:= wFlags
{or SDL_WINDOW_FULLSCREEN} else wFlags
:= wFlags
or SDL_WINDOW_RESIZABLE
;
110 if (not gFullscreen
) and (not preserveGL
) and gWinMaximized
then wFlags
:= wFlags
or SDL_WINDOW_MAXIMIZED
else gWinMaximized
:= false;
114 mode
.w
:= gScreenWidth
;
115 mode
.h
:= gScreenHeight
;
117 mode
.refresh_rate
:= 0;
118 mode
.driverdata
:= nil;
119 if (SDL_GetClosestDisplayMode(0, @mode
, @cmode
) = nil) then
121 e_WriteLog('SDL: cannot find display mode for '+IntToStr(gScreenWidth
), TMsgType
.Notify
);
123 gScreenHeight
:= 600;
127 e_WriteLog('SDL: found display mode for '+IntToStr(gScreenWidth
)+'x'+IntToStr(gScreenHeight
)+': '+IntToStr(cmode
.w
)+'x'+IntToStr(cmode
.h
), TMsgType
.Notify
);
128 gScreenWidth
:= cmode
.w
;
129 gScreenHeight
:= cmode
.h
;
133 if (preserveGL
) and (h_Wnd
<> nil) and (not gFullscreen
) and (not wasFullscreen
) then
135 //SDL_SetWindowMaximumSize(h_Wnd, gScreenWidth, gScreenHeight);
136 //SDL_SetWindowDisplayMode(h_Wnd, @cmode);
137 if (wMaximized
) then SDL_RestoreWindow(h_Wnd
);
139 gWinMaximized
:= false;
140 SDL_SetWindowSize(h_Wnd
, gScreenWidth
, gScreenHeight
);
141 //SDL_SetWindowFullscreen(h_Wnd, SDL_WINDOW_FULLSCREEN);
142 //SDL_SetWindowFullscreen(h_Wnd, 0);
146 KillGLWindow(preserveGL
);
147 h_Wnd
:= SDL_CreateWindow(PChar(wTitle
), gWinRealPosX
, gWinRealPosY
, gScreenWidth
, gScreenHeight
, wFlags
);
149 SDL_SetWindowFullscreen(h_Wnd
, SDL_WINDOW_FULLSCREEN
);
150 if (h_Wnd
= nil) then exit
;
152 wasFullscreen
:= gFullscreen
;
154 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
155 SDL_ShowCursor(SDL_DISABLE
);
156 if (gFullscreen
) then
160 SDL_GetWindowSize(h_Wnd
, @nw
, @nh
);
161 if (nw
> 128) and (nh
> 128) then
163 e_WriteLog('SDL: fullscreen window got size '+IntToStr(nw
)+'x'+IntToStr(nh
)+': '+IntToStr(gScreenWidth
)+'x'+IntToStr(gScreenHeight
), TMsgType
.Notify
);
169 e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw
)+'x'+IntToStr(nh
), TMsgType
.Notify
);
172 fuiScrWdt
:= gScreenWidth
;
173 fuiScrHgt
:= gScreenHeight
;
174 if (h_GL
<> nil) and (not preserveGL
) then begin if (assigned(oglInitCB
)) then oglInitCB(); end;
181 function GetDisplayModes (dbpp
: LongWord; var selres
: LongWord): SSArray
;
183 mode
: TSDL_DisplayMode
;
184 res
, i
, k
, n
, pw
, ph
: Integer;
186 SetLength(result
, 0);
187 {$IFDEF HEADLESS}exit
;{$ENDIF}
189 n
:= SDL_GetNumDisplayModes(0);
193 res
:= SDL_GetDisplayMode(0, i
, @mode
);
194 if res
< 0 then continue
;
195 if SDL_BITSPERPIXEL(mode
.format
) = gBPP
then continue
;
196 if (mode
.w
= pw
) and (mode
.h
= ph
) then continue
;
197 if (mode
.w
= gScreenWidth
) and (mode
.h
= gScreenHeight
) then
200 SetLength(result
, k
);
201 result
[k
-1] := IntToStr(mode
.w
) + 'x' + IntToStr(mode
.h
);
202 pw
:= mode
.w
; ph
:= mode
.h
205 e_WriteLog('SDL: Got ' + IntToStr(k
) + ' resolutions.', TMsgType
.Notify
);
209 procedure Sleep (ms
: LongWord);
215 procedure ChangeWindowSize ();
217 e_LogWritefln(' ChangeWindowSize: (ws=%dx%d) (ss=%dx%d)', [gWinSizeX
, gWinSizeY
, gScreenWidth
, gScreenHeight
]);
218 gWinSizeX
:= gScreenWidth
;
219 gWinSizeY
:= gScreenHeight
;
220 {$IF not DEFINED(HEADLESS)}
221 fuiScrWdt
:= gScreenWidth
;
222 fuiScrHgt
:= gScreenHeight
;
223 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
224 g_Game_SetupScreenSize();
226 g_Game_ClearLoading();
231 function g_Window_SetSize (w
, h
: Word; fullscreen
: Boolean): Boolean;
232 {$IF not DEFINED(HEADLESS)}
238 {$IF not DEFINED(HEADLESS)}
241 if (gScreenWidth
<> w
) or (gScreenHeight
<> h
) then
249 if (gFullscreen
<> fullscreen
) then
253 gFullscreen
:= fullscreen
;
259 g_Window_SetDisplay(preserve
);
266 function WindowEventHandler (constref ev
: TSDL_WindowEvent
): Boolean;
268 wActivate
, wDeactivate
: Boolean;
272 wDeactivate
:= false;
275 SDL_WINDOWEVENT_MOVED
:
277 if not (gFullscreen
or gWinMaximized
) then
279 gWinRealPosX
:= ev
.data1
;
280 gWinRealPosY
:= ev
.data2
;
284 SDL_WINDOWEVENT_MINIMIZED
:
287 if not wMinimized
then
289 e_ResizeWindow(0, 0);
291 if g_debug_WinMsgs
then
293 g_Console_Add('Now minimized');
294 e_WriteLog('[DEBUG] WinMsgs: Now minimized', TMsgType
.Notify
);
300 SDL_WINDOWEVENT_RESIZED
:
302 e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth
, gScreenHeight
, Integer(ev
.data1
), Integer(ev
.data2
)]);
303 {if (gFullscreen) then
305 e_LogWriteln(' fullscreen fix applied.');
306 if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
308 SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
313 gScreenWidth
:= ev
.data1
;
314 gScreenHeight
:= ev
.data2
;
318 if g_debug_WinMsgs
then
320 g_Console_Add('Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
));
321 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
), TMsgType
.Notify
);
325 SDL_WINDOWEVENT_EXPOSED
:
328 SDL_WINDOWEVENT_MAXIMIZED
:
333 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
337 if (not gWinMaximized
) and (not gFullscreen
) then
339 gWinMaximized
:= true;
340 if g_debug_WinMsgs
then
342 g_Console_Add('Now maximized');
343 e_WriteLog('[DEBUG] WinMsgs: Now maximized', TMsgType
.Notify
);
348 SDL_WINDOWEVENT_RESTORED
:
353 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
357 gWinMaximized
:= false;
358 if g_debug_WinMsgs
then
360 g_Console_Add('Now restored');
361 e_WriteLog('[DEBUG] WinMsgs: Now restored', TMsgType
.Notify
);
365 SDL_WINDOWEVENT_FOCUS_GAINED
:
368 //e_WriteLog('window gained focus!', MSG_NOTIFY);
371 SDL_WINDOWEVENT_FOCUS_LOST
:
375 //e_WriteLog('window lost focus!', MSG_NOTIFY);
383 e_WriteLog('deactivating window', TMsgType
.Notify
);
384 e_EnableInput
:= false;
385 e_ClearInputBuffer();
387 if gMuteWhenInactive
then
389 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
390 e_MuteChannels(true);
393 if g_debug_WinMsgs
then
395 g_Console_Add('Now inactive');
396 e_WriteLog('[DEBUG] WinMsgs: Now inactive', TMsgType
.Notify
);
401 if assigned(winBlurCB
) then winBlurCB();
404 else if wActivate
then
406 if not gWinActive
then
408 //e_WriteLog('activating window', MSG_NOTIFY);
409 e_EnableInput
:= true;
411 if gMuteWhenInactive
then
413 //e_WriteLog('activating sounds', MSG_NOTIFY);
414 e_MuteChannels(false);
417 if g_debug_WinMsgs
then
419 g_Console_Add('Now active');
420 e_WriteLog('[DEBUG] WinMsgs: Now active', TMsgType
.Notify
);
424 if assigned(winFocusCB
) then winFocusCB();
430 function EventHandler (var ev
: TSDL_Event
): Boolean;
440 result
:= WindowEventHandler(ev
.window
);
444 if (gExit
<> EXIT_QUIT
) then
446 if not wLoadingProgress
then
453 wLoadingQuit
:= true;
459 SDL_KEYDOWN
, SDL_KEYUP
:
461 key
:= ev
.key
.keysym
.scancode
;
462 down
:= (ev
.type_
= SDL_KEYDOWN
);
463 {$IF not DEFINED(HEADLESS)}
464 if fuiOnSDLEvent(ev
) then
466 // event eaten, but...
467 if not down
then e_KeyUpDown(key
, false);
471 if down
then KeyPress(key
);
472 e_KeyUpDown(key
, down
);
475 {$IF not DEFINED(HEADLESS)}
476 SDL_MOUSEBUTTONDOWN
, SDL_MOUSEBUTTONUP
, SDL_MOUSEWHEEL
, SDL_MOUSEMOTION
:
482 Utf8ToUnicode(@uc
, PChar(ev
.text.text), 1);
484 if (keychr
> 127) then keychr
:= Word(wchar2win(WideChar(keychr
)));
485 if (keychr
> 0) and (keychr
<= 255) then CharPress(AnsiChar(keychr
));
488 // other key presses and joysticks are handled in e_input
493 procedure SwapBuffers ();
495 {$IF not DEFINED(HEADLESS)}
496 SDL_GL_SwapWindow(h_Wnd
);
501 function CreateGLWindow (Title
: PChar): Boolean;
505 gWinSizeX
:= gScreenWidth
;
506 gWinSizeY
:= gScreenHeight
;
508 {$IF not DEFINED(HEADLESS)}
511 e_WriteLog('Creating window', TMsgType
.Notify
);
513 if not g_Window_SetDisplay() then
516 e_WriteLog('Window creation error (resolution not supported?)', TMsgType
.Fatal
);
520 {$IF not DEFINED(HEADLESS)}
521 h_GL
:= SDL_GL_CreateContext(h_Wnd
);
522 if (h_GL
= nil) then exit
;
523 fuiScrWdt
:= gScreenWidth
;
524 fuiScrHgt
:= gScreenHeight
;
525 if (assigned(oglInitCB
)) then oglInitCB();
529 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
537 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
538 function GetTimer (): Int64;
542 QueryPerformanceFrequency(F
);
543 QueryPerformanceCounter(C
);
544 result
:= Round(C
/F
*1000{000});
547 function GetTimer (): Int64;
553 if (ticksOverflow
= -1) then
560 if (lastTicks
> t
) then
562 // overflow, increment overflow ;-)
563 ticksOverflow
:= ticksOverflow
+(Int64($ffffffff)+Int64(1));
564 tt
:= (Int64($ffffffff)+Int64(1))+Int64(t
);
565 t
:= Uint32(tt
-lastTicks
);
569 result
:= ticksOverflow
+Int64(t
);
574 procedure ResetTimer ();
576 wNeedTimeReset
:= true;
580 procedure PushExitEvent ();
584 ev
.type_
:= SDL_QUITEV
;
590 prevLoadingUpdateTime
: UInt64 = 0;
592 procedure ProcessLoading (forceUpdate
: Boolean=false);
598 FillChar(ev
, sizeof(ev
), 0);
599 wLoadingProgress
:= true;
601 while (SDL_PollEvent(@ev
) > 0) do
604 if (ev
.type_
= SDL_QUITEV
) then break
;
608 if (ev
.type_
= SDL_QUITEV
) or (gExit
= EXIT_QUIT
) then
610 wLoadingProgress
:= false;
614 if not wMinimized
then
618 prevLoadingUpdateTime
:= getTimeMilli();
622 stt
:= getTimeMilli();
623 if (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= ProgressUpdateMSecs
) then
625 prevLoadingUpdateTime
:= stt
;
632 if g_Texture_Get('INTER', ID
) then
634 e_DrawSize(ID
, 0, 0, 0, false, false, gScreenWidth
, gScreenHeight
);
635 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
639 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
649 if NetMode
= NET_SERVER
then
655 if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then g_Net_Client_UpdateWhileLoading();
658 wLoadingProgress
:= false;
662 function g_ProcessMessages (): Boolean;
667 FillChar(ev
, SizeOf(ev
), 0);
668 while (SDL_PollEvent(@ev
) > 0) do
670 result
:= EventHandler(ev
);
671 if (ev
.type_
= SDL_QUITEV
) then exit
;
677 function ProcessMessage (): Boolean;
681 result
:= g_ProcessMessages();
684 Time_Delta
:= Time
-Time_Old
;
688 if wNeedTimeReset
then
691 wNeedTimeReset
:= false;
694 g_Map_ProfilersBegin();
695 g_Mons_ProfilersBegin();
697 t
:= Time_Delta
div 28;
703 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
704 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
710 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
711 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
714 g_Map_ProfilersEnd();
715 g_Mons_ProfilersEnd();
723 if (gExit
= EXIT_QUIT
) then
729 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
732 Time_Old
:= Time
-(Time_Delta
mod 28);
733 if (not wMinimized
) then
741 Sleep(1); // release time slice, so we won't eat 100% CPU
748 procedure ReDrawWindow ();
754 procedure g_SetVSync (vsync
: Boolean);
755 {$IF not DEFINED(HEADLESS)}
760 {$IF not DEFINED(HEADLESS)}
761 if vsync
then v
:= 1 else v
:= 0;
762 if (SDL_GL_SetSwapInterval(v
) <> 0) then
764 e_WriteLog('oops; can''t change vsync option, restart required', TMsgType
.Warning
);
768 if vsync
then e_WriteLog('VSync: ON', TMsgType
.Notify
) else e_WriteLog('VSync: OFF', TMsgType
.Notify
);
774 procedure InitOpenGL ();
776 {$IF not DEFINED(HEADLESS)}
777 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 2);
778 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
779 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 8);
780 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 8);
781 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 8);
782 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, 16);
783 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
784 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE
, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
789 function glHasExtension (const name
: AnsiString): Boolean;
794 extName
: ShortString;
797 if (Length(name
) = 0) then exit
;
798 exts
:= glGetString(GL_EXTENSIONS
);
799 if (exts
= nil) then exit
;
800 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
801 while (exts
[0] <> #0) do
803 if gwin_dump_extensions
then
806 while (exts
[i
] <> #0) and (exts
[i
] <> ' ') do Inc(i
);
809 e_WriteLog('FUUUUUUUUUUUUU', TMsgType
.Warning
);
813 Move(exts
^, extName
[1], i
);
814 extName
[0] := Char(i
);
815 e_WriteLog(Format('EXT: %s', [extName
]), TMsgType
.Notify
);
819 for i
:= 0 to length(name
)-1 do
821 if (exts
[i
] = #0) then begin found
:= false; break
; end;
822 if (exts
[i
] <> name
[i
+1]) then begin found
:= false; break
; end;
824 if found
and ((exts
[Length(name
)] = #0) or (exts
[Length(name
)] = ' ')) then begin result
:= true; exit
; end;
825 while (exts
[0] <> #0) and (exts
[0] <> ' ') do Inc(exts
);
826 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
831 function SDLMain (): Integer;
834 {$IF not DEFINED(HEADLESS)}
843 e_NoGraphics
:= true;
845 if (not g_holmes_imfunctional
) then
848 uiContext
.font
:= 'win14';
853 while (idx
<= ParamCount
) do
855 arg
:= ParamStr(idx
);
857 if arg
= '--opengl-dump-exts' then gwin_dump_extensions
:= true;
858 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
859 if arg
= '--jah' then g_profile_history_size
:= 100;
860 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
861 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
863 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
864 if arg
= '--profile-coldet' then g_profile_collision
:= true;
865 if arg
= '--profile-los' then g_profile_los
:= true;
867 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
868 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
869 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
870 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
871 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
872 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
874 {.$IF DEFINED(D2F_DEBUG)}
875 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
878 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
880 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
882 if (idx
<= ParamCount
) then
884 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
889 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
891 if (idx
<= ParamCount
) then
894 val(ParamStr(idx
), itmp
, valres
);
896 if (valres
= 0) and (not g_holmes_imfunctional
) then
899 8: uiContext
.font
:= 'win8';
900 14: uiContext
.font
:= 'win14';
901 16: uiContext
.font
:= 'win16';
913 if (arg
= '--game-scale') or (arg
= '-game-scale') then
915 if (idx
<= ParamCount
) then
917 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
922 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
924 mdfo
:= createDiskFile('mapdef.txt');
925 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
931 e_WriteLog('Initializing OpenGL', TMsgType
.Notify
);
934 e_WriteLog('Creating GL window', TMsgType
.Notify
);
935 if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION
]))) then
941 {EnumDisplayModes();}
944 //gwin_k8_enable_light_experiments := false;
945 gwin_has_stencil
:= false;
946 glLegacyNPOT
:= false;
947 gwin_dump_extensions
:= false;
949 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE
, @ltmp
);
950 e_LogWritefln('stencil buffer size: %s', [ltmp
]);
951 gwin_has_stencil
:= (ltmp
> 0);
953 if not glHasExtension('GL_ARB_texture_non_power_of_two') then
955 e_WriteLog('NPOT textures: NO', TMsgType
.Warning
);
956 glLegacyNPOT
:= true;
960 e_WriteLog('NPOT textures: YES', TMsgType
.Notify
);
961 glLegacyNPOT
:= false;
963 gwin_dump_extensions
:= false;
967 Time_Old
:= GetTimer();
970 if (ParamCount
> 0) then g_Game_Process_Params();
973 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
975 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
978 while not ProcessMessage() do begin end;