DEADSOFTWARE

rewritten dyntree visitor; seems to fix segfaults (but i don't know why)
[d2df-sdl.git] / src / game / g_window.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, either version 3 of the License, or
6 * (at your option) any later version.
7 *
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.
12 *
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/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_window;
19 interface
21 uses
22 wadreader;
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();
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;
39 var
40 gwin_dump_extensions: Boolean = false;
41 gwin_has_stencil: Boolean = false;
42 gwin_k8_enable_light_experiments: Boolean = false;
44 implementation
46 uses
47 {$IFDEF WINDOWS}Windows,{$ENDIF}
48 SDL2, GL, GLExt, e_graphics, e_log, g_main,
49 g_console, SysUtils, e_input, g_options, g_game,
50 g_basic, g_textures, e_sound, g_sound, g_menu, ENet, g_net,
51 g_map;
53 var
54 h_Wnd: PSDL_Window;
55 h_GL: TSDL_GLContext;
56 wFlags: LongWord = 0;
57 Time, Time_Delta, Time_Old: Int64;
58 flag: Boolean;
59 wTitle: PChar = nil;
60 wNeedTimeReset: Boolean = False;
61 //wWindowCreated: Boolean = False;
62 //wCursorShown: Boolean = False;
63 wMinimized: Boolean = False;
64 //wNeedFree: Boolean = True;
65 wLoadingProgress: Boolean = False;
66 wLoadingQuit: Boolean = False;
67 {wWinPause: Byte = 0;}
68 {$IFNDEF WINDOWS}
69 ticksOverflow: Int64 = -1;
70 lastTicks: Uint32 = 0; // to detect overflow
71 {$ENDIF}
73 const
74 // TODO: move this to a separate file
75 CP1251: array [0..127] of Word = (
76 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
77 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
78 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
79 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
80 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
81 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
82 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
83 $0440,$0441,$0442,$0443,$0444,$0445,$0446,$0447,$0448,$0449,$044A,$044B,$044C,$044D,$044E,$044F
84 );
86 // TODO: make a transition table or something
87 function WCharToCP1251(wc: Word): Word;
88 var
89 n: Word;
90 begin
91 Result := 0;
92 for n := 0 to 127 do
93 if CP1251[n] = wc then begin Result := n; break end;
94 Result := Result + 128;
95 end;
97 function g_Window_SetDisplay(PreserveGL: Boolean = False): Boolean;
98 var
99 mode, cmode: TSDL_DisplayMode;
100 begin
101 {$IFDEF HEADLESS}
102 Result := True;
103 Exit;
104 {$ENDIF}
106 Result := False;
108 e_WriteLog('Setting display mode...', MSG_NOTIFY);
110 wFlags := SDL_WINDOW_OPENGL or SDL_WINDOW_RESIZABLE;
111 if gFullscreen then wFlags := wFlags or SDL_WINDOW_FULLSCREEN;
112 if gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED;
114 if h_Wnd <> nil then
115 begin
116 SDL_DestroyWindow(h_Wnd);
117 h_Wnd := nil;
118 end;
120 if gFullscreen then
121 begin
122 mode.w := gScreenWidth;
123 mode.h := gScreenHeight;
124 mode.format := 0;
125 mode.refresh_rate := 0;
126 mode.driverdata := nil;
127 if SDL_GetClosestDisplayMode(0, @mode, @cmode) = nil then
128 begin
129 gScreenWidth := 800;
130 gScreenHeight := 600;
131 end
132 else
133 begin
134 gScreenWidth := cmode.w;
135 gScreenHeight := cmode.h;
136 end;
137 end;
139 h_Wnd := SDL_CreateWindow(PChar(wTitle), gWinRealPosX, gWinRealPosY, gScreenWidth, gScreenHeight, wFlags);
140 if h_Wnd = nil then Exit;
142 SDL_GL_MakeCurrent(h_Wnd, h_GL);
143 SDL_ShowCursor(SDL_DISABLE);
145 Result := True;
146 end;
148 procedure ReShowCursor();
149 begin
150 // TODO: what was this for?
151 end;
153 function GetDisplayModes(dBPP: DWORD; var SelRes: DWORD): SArray;
154 var
155 mode: TSDL_DisplayMode;
156 res, i, k, n, pw, ph: Integer;
157 begin
158 SetLength(Result, 0);
159 {$IFDEF HEADLESS}Exit;{$ENDIF}
160 k := 0; SelRes := 0;
161 n := SDL_GetNumDisplayModes(0);
162 pw := 0; ph := 0;
163 for i := 0 to n do
164 begin
165 res := SDL_GetDisplayMode(0, i, @mode);
166 if res < 0 then continue;
167 if SDL_BITSPERPIXEL(mode.format) = gBPP then continue;
168 if (mode.w = pw) and (mode.h = ph) then continue;
169 if (mode.w = gScreenWidth) and (mode.h = gScreenHeight) then
170 SelRes := k;
171 Inc(k);
172 SetLength(Result, k);
173 Result[k-1] := IntToStr(mode.w) + 'x' + IntToStr(mode.h);
174 pw := mode.w; ph := mode.h
175 end;
177 e_WriteLog('SDL: Got ' + IntToStr(k) + ' resolutions.', MSG_NOTIFY);
178 end;
180 procedure Sleep(ms: LongWord);
181 begin
182 SDL_Delay(ms);
183 end;
185 procedure ChangeWindowSize();
186 begin
187 gWinSizeX := gScreenWidth;
188 gWinSizeY := gScreenHeight;
189 {$IFDEF HEADLESS}Exit;{$ENDIF}
190 e_ResizeWindow(gScreenWidth, gScreenHeight);
191 g_Game_SetupScreenSize();
192 g_Menu_Reset();
193 g_Game_ClearLoading();
194 end;
196 function g_Window_SetSize(W, H: Word; FScreen: Boolean): Boolean;
197 var
198 Preserve: Boolean;
199 begin
200 Result := False;
201 {$IFDEF HEADLESS}Exit;{$ENDIF}
202 Preserve := False;
204 if (gScreenWidth <> W) or (gScreenHeight <> H) then
205 begin
206 Result := True;
207 gScreenWidth := W;
208 gScreenHeight := H;
209 end;
211 if gFullscreen <> FScreen then
212 begin
213 Result := True;
214 gFullscreen := FScreen;
215 Preserve := True;
216 end;
218 if Result then
219 begin
220 g_Window_SetDisplay(Preserve);
221 ChangeWindowSize();
222 end;
223 end;
225 function WindowEventHandler(ev: TSDL_WindowEvent): Boolean;
226 var
227 wActivate, wDeactivate: Boolean;
228 begin
229 Result := False;
230 wActivate := False;
231 wDeactivate := False;
233 case ev.event of
234 SDL_WINDOWEVENT_MOVED:
235 begin
236 if not (gFullscreen or gWinMaximized) then
237 begin
238 gWinRealPosX := ev.data1;
239 gWinRealPosY := ev.data2;
240 end;
241 end;
243 SDL_WINDOWEVENT_MINIMIZED:
244 begin
245 if not wMinimized then
246 begin
247 e_ResizeWindow(0, 0);
248 wMinimized := True;
250 if g_debug_WinMsgs then
251 begin
252 g_Console_Add('Now minimized');
253 e_WriteLog('[DEBUG] WinMsgs: Now minimized', MSG_NOTIFY);
254 end;
255 wDeactivate := True;
256 end;
257 end;
259 SDL_WINDOWEVENT_RESIZED:
260 begin
261 gScreenWidth := ev.data1;
262 gScreenHeight := ev.data2;
263 ChangeWindowSize();
264 SwapBuffers();
265 if g_debug_WinMsgs then
266 begin
267 g_Console_Add('Resized to ' + IntToStr(ev.data1) + 'x' + IntToStr(ev.data2));
268 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev.data1) + 'x' + IntToStr(ev.data2), MSG_NOTIFY);
269 end;
270 end;
272 SDL_WINDOWEVENT_EXPOSED:
273 SwapBuffers();
275 SDL_WINDOWEVENT_MAXIMIZED:
276 begin
277 if wMinimized then
278 begin
279 e_ResizeWindow(gScreenWidth, gScreenHeight);
280 wMinimized := False;
281 wActivate := True;
282 end;
283 if not gWinMaximized then
284 begin
285 gWinMaximized := True;
286 if g_debug_WinMsgs then
287 begin
288 g_Console_Add('Now maximized');
289 e_WriteLog('[DEBUG] WinMsgs: Now maximized', MSG_NOTIFY);
290 end;
291 end;
292 end;
294 SDL_WINDOWEVENT_RESTORED:
295 begin
296 if wMinimized then
297 begin
298 e_ResizeWindow(gScreenWidth, gScreenHeight);
299 wMinimized := False;
300 wActivate := True;
301 end;
302 if gWinMaximized then
303 gWinMaximized := False;
304 if g_debug_WinMsgs then
305 begin
306 g_Console_Add('Now restored');
307 e_WriteLog('[DEBUG] WinMsgs: Now restored', MSG_NOTIFY);
308 end;
309 end;
311 SDL_WINDOWEVENT_FOCUS_GAINED:
312 begin
313 wActivate := True;
314 //e_WriteLog('window gained focus!', MSG_NOTIFY);
315 end;
317 SDL_WINDOWEVENT_FOCUS_LOST:
318 begin
319 wDeactivate := True;
320 //e_WriteLog('window lost focus!', MSG_NOTIFY);
321 end;
322 end;
324 if wDeactivate then
325 begin
326 if gWinActive then
327 begin
328 e_WriteLog('deactivating window', MSG_NOTIFY);
329 e_EnableInput := False;
330 e_ClearInputBuffer();
332 if gMuteWhenInactive then
333 begin
334 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
335 e_MuteChannels(True);
336 end;
338 if g_debug_WinMsgs then
339 begin
340 g_Console_Add('Now inactive');
341 e_WriteLog('[DEBUG] WinMsgs: Now inactive', MSG_NOTIFY);
342 end;
344 gWinActive := False;
345 end;
346 end
347 else if wActivate then
348 begin
349 if not gWinActive then
350 begin
351 //e_WriteLog('activating window', MSG_NOTIFY);
352 e_EnableInput := True;
354 if gMuteWhenInactive then
355 begin
356 //e_WriteLog('activating sounds', MSG_NOTIFY);
357 e_MuteChannels(False);
358 end;
360 if g_debug_WinMsgs then
361 begin
362 g_Console_Add('Now active');
363 e_WriteLog('[DEBUG] WinMsgs: Now active', MSG_NOTIFY);
364 end;
366 gWinActive := True;
367 end;
368 end;
369 end;
371 function EventHandler(ev: TSDL_Event): Boolean;
372 var
373 key, keychr: Word;
374 uc: UnicodeChar;
375 //joy: Integer;
376 begin
377 Result := False;
378 case ev.type_ of
379 SDL_WINDOWEVENT:
380 Result := WindowEventHandler(ev.window);
382 SDL_QUITEV:
383 begin
384 if gExit <> EXIT_QUIT then
385 begin
386 if not wLoadingProgress then
387 begin
388 g_Game_Free();
389 g_Game_Quit();
390 end
391 else
392 wLoadingQuit := True;
393 end;
394 Result := True;
395 end;
397 SDL_KEYDOWN:
398 begin
399 key := ev.key.keysym.scancode;
400 KeyPress(key);
401 end;
403 SDL_TEXTINPUT:
404 begin
405 Utf8ToUnicode(@uc, PChar(ev.text.text), 1);
406 keychr := Word(uc);
407 if (keychr > 127) then
408 keychr := WCharToCP1251(keychr);
409 CharPress(Chr(keychr));
410 end;
412 // other key presses and joysticks are handled in e_input
413 end;
414 end;
416 procedure SwapBuffers();
417 begin
418 {$IFDEF HEADLESS}Exit;{$ENDIF}
419 SDL_GL_SwapWindow(h_Wnd);
420 end;
422 procedure KillGLWindow();
423 begin
424 if h_Wnd <> nil then SDL_DestroyWindow(h_Wnd);
425 if h_GL <> nil then SDL_GL_DeleteContext(h_GL);
426 h_Wnd := nil;
427 h_GL := nil;
428 //wWindowCreated := False;
429 end;
431 function CreateGLWindow(Title: PChar): Boolean;
432 //var
433 // flags: LongWord;
434 begin
435 Result := False;
437 gWinSizeX := gScreenWidth;
438 gWinSizeY := gScreenHeight;
440 wTitle := Title;
441 e_WriteLog('Creating window', MSG_NOTIFY);
443 if not g_Window_SetDisplay() then
444 begin
445 KillGLWindow();
446 e_WriteLog('Window creation error (resolution not supported?)', MSG_FATALERROR);
447 exit;
448 end;
450 {$IFNDEF HEADLESS}
451 h_Gl := SDL_GL_CreateContext(h_Wnd);
452 if h_Gl = nil then Exit;
453 {$ENDIF}
454 //wWindowCreated := True;
456 e_ResizeWindow(gScreenWidth, gScreenHeight);
457 e_InitGL();
459 Result := True;
460 end;
462 {$IFDEF WINDOWS}
463 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
464 function GetTimer(): Int64;
465 var
466 F, C: Int64;
467 begin
468 QueryPerformanceFrequency(F);
469 QueryPerformanceCounter(C);
470 Result := Round(C/F*1000{000});
471 end;
472 {$ELSE}
473 function GetTimer(): Int64;
474 var
475 t: Uint32;
476 tt: Int64;
477 begin
478 t := SDL_GetTicks() {* 1000}; // TODO: do we really need microseconds here? k8: NOPE!
479 if ticksOverflow = -1 then
480 begin
481 ticksOverflow := 0;
482 lastTicks := t;
483 end
484 else
485 begin
486 if lastTicks > t then
487 begin
488 // overflow, increment overflow ;-)
489 ticksOverflow := ticksOverflow+(Int64($ffffffff)+Int64(1));
490 tt := (Int64($ffffffff)+Int64(1))+Int64(t);
491 t := Uint32(tt-lastTicks);
492 end;
493 end;
494 lastTicks := t;
495 result := ticksOverflow+Int64(t);
496 end;
497 {$ENDIF}
499 procedure ResetTimer();
500 begin
501 wNeedTimeReset := True;
502 end;
504 procedure PushExitEvent();
505 var
506 ev: TSDL_Event;
507 begin
508 ev.type_ := SDL_QUITEV;
509 SDL_PushEvent(@ev);
510 end;
512 procedure ProcessLoading();
513 var
514 ev: TSDL_Event;
515 ID: DWORD;
516 begin
517 FillChar(ev, SizeOf(ev), 0);
518 //wNeedFree := False;
519 wLoadingProgress := True;
520 while SDL_PollEvent(@ev) > 0 do
521 begin
522 if (ev.type_ = SDL_QUITEV) then
523 break;
524 end;
525 //wNeedFree := True;
527 if (ev.type_ = SDL_QUITEV) or (gExit = EXIT_QUIT) then
528 begin
529 wLoadingProgress := False;
530 exit;
531 end;
533 if not wMinimized then
534 begin
535 if g_Texture_Get('INTER', ID) then
536 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
537 else
538 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
540 DrawLoadingStat();
541 SwapBuffers();
543 ReShowCursor();
544 end;
546 e_SoundUpdate();
548 if NetMode = NET_SERVER then
549 g_Net_Host_Update
550 else
551 if (NetMode = NET_CLIENT) and (NetState <> NET_STATE_AUTH) then
552 g_Net_Client_UpdateWhileLoading;
553 wLoadingProgress := False;
554 end;
556 function ProcessMessage(): Boolean;
557 var
558 i, t: Integer;
559 ev: TSDL_Event;
560 begin
561 Result := False;
562 FillChar(ev, SizeOf(ev), 0);
564 while SDL_PollEvent(@ev) > 0 do
565 begin
566 Result := EventHandler(ev);
567 if ev.type_ = SDL_QUITEV then exit;
568 end;
570 Time := GetTimer();
571 Time_Delta := Time - Time_Old;
573 flag := False;
575 if wNeedTimeReset then
576 begin
577 Time_Delta := 28{(27777 div 1000)};
578 wNeedTimeReset := False;
579 end;
581 g_Map_ProfilersBegin();
583 t := Time_Delta div 28{(27777 div 1000)};
584 if t > 0 then
585 begin
586 flag := True;
587 for i := 1 to t do
588 begin
589 if NetMode = NET_SERVER then g_Net_Host_Update()
590 else if NetMode = NET_CLIENT then g_Net_Client_Update();
591 Update();
592 end;
593 end
594 else
595 begin
596 if NetMode = NET_SERVER then g_Net_Host_Update()
597 else if NetMode = NET_CLIENT then g_Net_Client_Update();
598 end;
600 g_Map_ProfilersEnd();
602 if wLoadingQuit then
603 begin
604 g_Game_Free();
605 g_Game_Quit();
606 end;
608 if gExit = EXIT_QUIT then
609 begin
610 Result := True;
611 Exit;
612 end;
614 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ:
615 if flag then
616 begin
617 Time_Old := Time - (Time_Delta mod 28{(27777 div 1000)});
618 if (not wMinimized) then
619 begin
620 Draw();
621 SwapBuffers();
622 ReShowCursor();
623 end;
624 end
625 else
626 Sleep(1);
628 e_SoundUpdate();
629 end;
631 procedure ReDrawWindow;
632 begin
633 SwapBuffers();
634 ReShowCursor();
635 end;
637 procedure InitOpenGL(VSync: Boolean);
638 var
639 v: Byte;
640 begin
641 {$IFDEF HEADLESS}Exit;{$ENDIF}
642 if VSync then v := 1 else v := 0;
643 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
644 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
645 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
646 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
647 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
648 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
649 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
650 if gwin_k8_enable_light_experiments then
651 begin
652 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); // lights; it is enough to have 1-bit stencil buffer for lighting
653 end;
654 SDL_GL_SetSwapInterval(v);
655 end;
657 function glHasExtension (name: AnsiString): Boolean;
658 var
659 exts: PChar;
660 i: Integer;
661 found: Boolean;
662 extName: ShortString;
663 begin
664 result := false;
665 if length(name) = 0 then exit;
666 exts := glGetString(GL_EXTENSIONS);
667 if exts = nil then exit;
668 while (exts[0] <> #0) and (exts[0] = ' ') do Inc(exts);
669 while exts[0] <> #0 do
670 begin
671 if gwin_dump_extensions then
672 begin
673 i := 0;
674 while (exts[i] <> #0) and (exts[i] <> ' ') do Inc(i);
675 if i > 255 then
676 begin
677 e_WriteLog('FUUUUUUUUUUUUU', MSG_WARNING);
678 end
679 else
680 begin
681 Move(exts^, extName[1], i);
682 extName[0] := Char(i);
683 e_WriteLog(Format('EXT: %s', [extName]), MSG_NOTIFY);
684 end;
685 end;
686 found := true;
687 for i := 0 to length(name)-1 do
688 begin
689 if exts[i] = #0 then begin found := false; break; end;
690 if exts[i] <> name[i+1] then begin found := false; break; end;
691 end;
692 if found and ((exts[length(name)] = #0) or (exts[length(name)] = ' ')) then begin result := true; exit; end;
693 while (exts[0] <> #0) and (exts[0] <> ' ') do Inc(exts);
694 while (exts[0] <> #0) and (exts[0] = ' ') do Inc(exts);
695 end;
696 end;
698 function SDLMain(): Integer;
699 var
700 idx: Integer;
701 ltmp: Integer;
702 begin
703 {$IFDEF HEADLESS}
704 e_NoGraphics := True;
705 {$ENDIF}
707 for idx := 1 to ParamCount do
708 begin
709 if ParamStr(idx) = '--opengl-dump-exts' then gwin_dump_extensions := true;
710 if ParamStr(idx) = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
711 if ParamStr(idx) = '--jah' then g_profile_history_size := 100;
712 if ParamStr(idx) = '--tree-draw' then gdbg_map_use_tree_draw := true;
713 if ParamStr(idx) = '--grid-draw' then gdbg_map_use_tree_draw := false;
714 if ParamStr(idx) = '--tree-coldet' then gdbg_map_use_tree_coldet := true;
715 if ParamStr(idx) = '--grid-coldet' then gdbg_map_use_tree_coldet := false;
716 end;
718 if gdbg_map_use_tree_draw then e_WriteLog('using TREE renderer', MSG_NOTIFY);
719 if not gdbg_map_use_tree_draw then e_WriteLog('using GRID renderer', MSG_NOTIFY);
721 if gdbg_map_use_tree_coldet then e_WriteLog('using TREE coldet', MSG_NOTIFY);
722 if not gdbg_map_use_tree_coldet then e_WriteLog('using GRID coldet', MSG_NOTIFY);
724 e_WriteLog('Initializing OpenGL', MSG_NOTIFY);
725 InitOpenGL(gVSync);
727 e_WriteLog('Creating GL window', MSG_NOTIFY);
728 if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION]))) then
729 begin
730 Result := 0;
731 exit;
732 end;
734 {EnumDisplayModes();}
736 if gwin_k8_enable_light_experiments then
737 begin
738 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, @ltmp);
739 e_WriteLog(Format('stencil buffer size: %d', [ltmp]), MSG_WARNING);
740 gwin_has_stencil := (ltmp > 0);
741 end
742 else
743 begin
744 gwin_has_stencil := false;
745 end;
747 if not glHasExtension('GL_ARB_texture_non_power_of_two') then
748 begin
749 e_WriteLog('Driver DID''T advertised NPOT textures support', MSG_WARNING);
750 glLegacyNPOT := true;
751 end
752 else
753 begin
754 e_WriteLog('Driver advertised NPOT textures support', MSG_NOTIFY);
755 glLegacyNPOT := false;
756 end;
757 gwin_dump_extensions := false;
759 Init();
760 Time_Old := GetTimer();
762 // Êîìàíäíàÿ ñòðîêà:
763 if ParamCount > 0 then
764 g_Game_Process_Params();
766 // Çàïðîñ ÿçûêà:
767 if (not gGameOn) and gAskLanguage then
768 g_Menu_AskLanguage();
770 e_WriteLog('Entering the main loop', MSG_NOTIFY);
772 while not ProcessMessage() do
773 { Main Loop } ;
775 Release();
776 KillGLWindow();
778 Result := 0;
779 end;
781 end.