-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgl_vidnt.pas
2017 lines (1668 loc) · 49.8 KB
/
gl_vidnt.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ------------------------------------------------------------------------------
// DelphiQuake, Copyright (C) 2005-2011 by Jim Valavanis
// E-Mail: [email protected]
//
// Copyright (C) 1996-1997 Id Software, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// ------------------------------------------------------------------------------
{$I dquake.inc}
unit gl_vidnt;
interface
uses
q_delphi,
Windows,
OpenGL12,
vid_h,
cvar,
gl_defs;
type
modestate_t = (MS_WINDOWED, MS_FULLSCREEN, MS_FULLDIB, MS_UNINIT);
vmode_t = record
_type: modestate_t;
width: integer;
height: integer;
modenum: integer;
dib: integer;
fullscreen: integer;
bpp: integer;
halfscreen: integer;
modedesc: array[0..16] of char;
end;
Pvmode_t = ^vmode_t;
procedure VID_HandlePause(pause: qboolean);
procedure VID_ForceLockState(lk: integer);
procedure VID_LockBuffer; // JVAL remove ?
procedure VID_UnlockBuffer; // JVAL remove ?
function VID_ForceUnlockedAndReturnState: integer;
procedure CenterWindow(hWndCenter: HWND; width, height: integer; lefttopjustify: BOOL);
function VID_SetWindowedMode(modenum: integer): qboolean;
function VID_SetFullDIBMode(modenum: integer): qboolean;
procedure VID_SetMode(modenum: integer; palette: PByteArray);
procedure VID_UpdateWindowStatus;
procedure CheckTextureExtensions;
procedure CheckArrayExtensions;
procedure CheckMultiTextureExtensions;
procedure GL_Init;
procedure GL_BeginRendering(x, y: PInteger; width, height: PInteger);
procedure GL_EndRendering;
procedure VID_SetPalette(palette: PByteArray);
procedure VID_SetDefaultMode;
procedure VID_Shutdown;
procedure ClearAllStates;
procedure AppActivate(fActive: BOOL; minimize: BOOL);
function MainWndProc(hWnd: HWND; Msg: longword; wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
function VID_NumModes: integer;
function VID_GetModePtr(modenum: integer): Pvmode_t;
function VID_GetModeDescription(mode: integer): PChar;
function VID_GetExtModeDescription(mode: integer): PChar;
procedure VID_DescribeCurrentMode_f;
procedure VID_DescribeMode_f;
procedure VID_DescribeModes_f;
procedure VID_InitFullDIB(inst: THandle);
function VID_Is8bit: qboolean;
procedure VID_Init8bitPalette;
procedure Check_Gamma(pal: PByteArray);
procedure VID_Init(palette: PByteArray);
procedure VID_MenuDraw;
procedure VID_MenuKey(key: integer);
var
gl_mtexable: qboolean = false;
var
texture_mode: integer = GL_LINEAR;
var
d_8to16table: array[0..255] of unsigned_short;
d_8to24table: array[0..255] of unsigned;
d_15to8table: array[0..65535] of byte;
texture_extension_number: Integer = 1;
vid: viddef_t; // global video state
isPermedia: qboolean = false;
gldepthmin, gldepthmax: single;
mainwindow: HWND;
window_center_x, window_center_y, window_x, window_y, window_width, window_height: integer;
window_rect: TRect;
bindTexFunc: BINDTEXFUNCPTR;
gl_ztrick: cvar_t = (name: 'gl_ztrick'; text: '1');
str_gl_vendor: PChar;
str_gl_renderer: PChar;
str_gl_version: PChar;
str_gl_extensions: PChar;
var
scr_skipupdate: qboolean;
DDActive: qboolean;
var
modestate: modestate_t = MS_UNINIT;
//====================================
var
vid_mode: cvar_t = (name: 'vid_mode'; text: '0'; archive: false);// Note that 0 is MODE_WINDOWED
_vid_default_mode: cvar_t = (name: '_vid_default_mode'; text: '0'; archive: true);// Note that 3 is MODE_FULLSCREEN_DEFAULT
_vid_default_mode_win: cvar_t = (name: '_vid_default_mode_win'; text: '3'; archive: true);
vid_wait: cvar_t = (name: 'vid_wait'; text: '0');
vid_nopageflip: cvar_t = (name: 'vid_nopageflip'; text: '0'; archive: true);
_vid_wait_override: cvar_t = (name: '_vid_wait_override'; text: '0'; archive: true);
vid_config_x: cvar_t = (name: 'vid_config_x'; text: '1024'; archive: true);
vid_config_y: cvar_t = (name: 'vid_config_y'; text: '768'; archive: true);
vid_stretch_by_2: cvar_t = (name: 'vid_stretch_by_2'; text: '1'; archive: true);
_windowed_mouse: cvar_t = (name: '_windowed_mouse'; text: '1'; archive: true);
implementation
uses
sys_win,
messages,
gl_screen,
gl_sky,
cd_win,
keys,
keys_h,
in_win,
common,
console,
sbar,
snd_win,
mmsystem,
cmd,
quakedef,
host_h,
menu,
wad,
gl_draw,
snd_dma;
const
MAX_MODE_LIST = 30;
VID_ROW_SIZE = 3;
WARP_WIDTH = 320;
WARP_HEIGHT = 200;
MAXWIDTH = 10000;
MAXHEIGHT = 10000;
BASEWIDTH = 320;
BASEHEIGHT = 200;
const
MODE_WINDOWED = 0;
NO_MODE = (MODE_WINDOWED - 1);
MODE_FULLSCREEN_DEFAULT = (MODE_WINDOWED + 1);
type
lmode_t = record
width: integer;
height: integer;
end;
Plmode_t = ^lmode_t;
const
lowresmodes: array[0..3] of lmode_t = (
(width: 320; height: 200),
(width: 320; height: 240),
(width: 400; height: 300),
(width: 512; height: 384)
);
var
modelist: array[0..MAX_MODE_LIST - 1] of vmode_t;
nummodes: integer = 0;
badmode: vmode_t;
var
gdevmode: DEVMODE;
vid_initialized: qboolean = false;
windowed, leavecurrentmode: qboolean;
vid_canalttab: qboolean = false;
vid_wassuspended: qboolean = false;
windowed_mouse: qboolean;
Icon: HICON;
var
DIBWidth, DIBHeight: integer;
WindowRect: TRect;
WindowStyle, ExWindowStyle: DWORD;
var
dibwindow: HWND;
var
vid_modenum: integer = NO_MODE;
vid_realmode: integer;
vid_default: integer = MODE_WINDOWED;
windowed_default: integer;
vid_curpal: array[0..256 * 3 - 1] of byte;
fullsbardraw: qboolean = false;
var
vid_gamma: single = 1.0;
var
baseRC: HGLRC;
maindc: HDC;
type
lp3DFXFUNC = procedure(i1, i2, i3, i4, i5: integer; const p: pointer);
var
is8bit: qboolean = false;
procedure VID_HandlePause(pause: qboolean);
begin
// JVAL remove
end;
procedure VID_ForceLockState(lk: integer);
begin
// JVAL remove
end;
procedure VID_LockBuffer;
begin
// JVAL remove
end;
procedure VID_UnlockBuffer;
begin
// JVAL remove
end;
function VID_ForceUnlockedAndReturnState: integer;
begin
result := 0;
end;
(*
void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
{
//JVAL remove
}
void D_EndDirectRect (int x, int y, int width, int height)
{
//JVAL remove
}
*)
procedure CenterWindow(hWndCenter: HWND; width, height: integer; lefttopjustify: BOOL);
var
CenterX, CenterY: integer;
begin
CenterX := (GetSystemMetrics(SM_CXSCREEN) - width) div 2;
CenterY := (GetSystemMetrics(SM_CYSCREEN) - height) div 2;
if CenterX > CenterY * 2 then
CenterX := CenterX div 2; // dual screens
if CenterX < 0 then
CenterX := 0;
if CenterY < 0 then
CenterY := 0;
SetWindowPos(hWndCenter, 0, CenterX, CenterY, 0, 0,
SWP_NOSIZE or SWP_NOZORDER or SWP_SHOWWINDOW or SWP_DRAWFRAME);
end;
function VID_SetWindowedMode(modenum: integer): qboolean;
var
dc: HDC;
width, height: integer;
rect: TRect;
begin
WindowRect.top := 0;
WindowRect.left := 0;
WindowRect.right := modelist[modenum].width;
WindowRect.bottom := modelist[modenum].height;
DIBWidth := modelist[modenum].width;
DIBHeight := modelist[modenum].height;
WindowStyle := WS_OVERLAPPED or WS_BORDER or WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX;
ExWindowStyle := 0;
rect := WindowRect;
AdjustWindowRectEx(rect, WindowStyle, false, 0);
width := rect.right - rect.left;
height := rect.bottom - rect.top;
// Create the DIB window
dibwindow := CreateWindowEx(
ExWindowStyle,
'WinQuake',
'GLQuake',
WindowStyle,
rect.left, rect.top,
width,
height,
0,
0,
global_hInstance,
nil);
if dibwindow = 0 then
Sys_Error('Couldn''t create DIB window');
// Center and show the DIB window
CenterWindow(dibwindow, WindowRect.right - WindowRect.left,
WindowRect.bottom - WindowRect.top, false);
ShowWindow(dibwindow, SW_SHOWDEFAULT);
UpdateWindow(dibwindow);
modestate := MS_WINDOWED;
// because we have set the background brush for the window to NULL
// (to avoid flickering when re-sizing the window on the desktop),
// we clear the window to black when created, otherwise it will be
// empty while Quake starts up.
dc := GetDC(dibwindow);
PatBlt(dc, 0, 0, WindowRect.right, WindowRect.bottom, BLACKNESS);
ReleaseDC(dibwindow, dc);
if vid.conheight > modelist[modenum].height then
vid.conheight := modelist[modenum].height;
if vid.conwidth > modelist[modenum].width then
vid.conwidth := modelist[modenum].width;
vid.width := vid.conwidth;
vid.height := vid.conheight;
vid.numpages := 2;
mainwindow := dibwindow;
SendMessage(mainwindow, WM_SETICON, WPARAM(true), LPARAM(Icon));
SendMessage(mainwindow, WM_SETICON, WPARAM(false), LPARAM(Icon));
result := true;
end;
function VID_SetFullDIBMode(modenum: integer): qboolean;
var
dc: HDC;
width, height: integer;
rect: TRect;
begin
if not leavecurrentmode then
begin
gdevmode.dmFields := DM_BITSPERPEL or DM_PELSWIDTH or DM_PELSHEIGHT;
gdevmode.dmBitsPerPel := modelist[modenum].bpp;
gdevmode.dmPelsWidth := (modelist[modenum].width shl modelist[modenum].halfscreen);
gdevmode.dmPelsHeight := modelist[modenum].height;
gdevmode.dmSize := SizeOf(gdevmode);
if ChangeDisplaySettings(gdevmode, CDS_FULLSCREEN) <> DISP_CHANGE_SUCCESSFUL then
Sys_Error('Couldn''t set fullscreen DIB mode');
end;
modestate := MS_FULLDIB;
WindowRect.top := 0;
WindowRect.left := 0;
WindowRect.right := modelist[modenum].width;
WindowRect.bottom := modelist[modenum].height;
DIBWidth := modelist[modenum].width;
DIBHeight := modelist[modenum].height;
WindowStyle := WS_POPUP;
ExWindowStyle := 0;
rect := WindowRect;
AdjustWindowRectEx(rect, WindowStyle, false, 0);
width := rect.right - rect.left;
height := rect.bottom - rect.top;
// Create the DIB window
dibwindow := CreateWindowEx(
ExWindowStyle,
'WinQuake',
'GLQuake',
WindowStyle,
rect.left, rect.top,
width,
height,
0,
0,
global_hInstance,
nil);
if dibwindow = 0 then
Sys_Error('Couldn''t create DIB window');
ShowWindow(dibwindow, SW_SHOWDEFAULT);
UpdateWindow(dibwindow);
// Because we have set the background brush for the window to NULL
// (to avoid flickering when re-sizing the window on the desktop), we
// clear the window to black when created, otherwise it will be
// empty while Quake starts up.
dc := GetDC(dibwindow);
PatBlt(dc, 0, 0, WindowRect.right, WindowRect.bottom, BLACKNESS);
ReleaseDC(dibwindow, dc);
if vid.conheight > modelist[modenum].height then
vid.conheight := modelist[modenum].height;
if vid.conwidth > modelist[modenum].width then
vid.conwidth := modelist[modenum].width;
vid.width := vid.conwidth;
vid.height := vid.conheight;
vid.numpages := 2;
// needed because we're not getting WM_MOVE messages fullscreen on NT
window_x := 0;
window_y := 0;
mainwindow := dibwindow;
SendMessage(mainwindow, WM_SETICON, WPARAM(true), LPARAM(Icon));
SendMessage(mainwindow, WM_SETICON, WPARAM(false), LPARAM(Icon));
result := true;
end;
procedure VID_SetMode(modenum: integer; palette: PByteArray);
var
temp: qboolean;
stat: qboolean;
msg: TMsg;
begin
if (windowed and (modenum <> 0)) or
(not windowed and (modenum < 1)) or
(not windowed and (modenum >= nummodes)) then
Sys_Error('Bad video mode'#10);
// so Con_Printfs don't mess us up by forcing vid and snd updates
temp := scr_disabled_for_loading;
scr_disabled_for_loading := true;
CDAudio_Pause;
// Set either the fullscreen or windowed mode
stat := false;
if modelist[modenum]._type = MS_WINDOWED then
begin
if (_windowed_mouse.value <> 0) and (key_dest = key_game) then
begin
stat := VID_SetWindowedMode(modenum);
IN_ActivateMouse;
IN_HideMouse;
end
else
begin
IN_DeactivateMouse;
IN_ShowMouse;
stat := VID_SetWindowedMode(modenum);
end;
end
else if modelist[modenum]._type = MS_FULLDIB then
begin
stat := VID_SetFullDIBMode(modenum);
IN_ActivateMouse;
IN_HideMouse;
end
else
Sys_Error('VID_SetMode: Bad mode type in modelist');
window_width := DIBWidth;
window_height := DIBHeight;
VID_UpdateWindowStatus;
CDAudio_Resume;
scr_disabled_for_loading := temp;
if not stat then
Sys_Error('Couldn''t set video mode');
// now we try to make sure we get the focus on the mode switch, because
// sometimes in some systems we don't. We grab the foreground, then
// finish setting up, pump all our messages, and sleep for a little while
// to let messages finish bouncing around the system, then we put
// ourselves at the top of the z order, then grab the foreground again,
// Who knows if it helps, but it probably doesn't hurt
SetForegroundWindow(mainwindow);
VID_SetPalette(palette);
vid_modenum := modenum;
Cvar_SetValue('vid_mode', vid_modenum);
while PeekMessage(msg, 0, 0, 0, PM_REMOVE) do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
Sleep(100);
SetWindowPos(mainwindow, HWND_TOP, 0, 0, 0, 0,
SWP_DRAWFRAME or SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW or
SWP_NOCOPYBITS);
SetForegroundWindow(mainwindow);
// fix the leftover Alt from any Alt-Tab or the like that switched us away
ClearAllStates;
if not msg_suppress_1 then
Con_SafePrintf('Video mode %s initialized.'#10, [VID_GetModeDescription(vid_modenum)]);
VID_SetPalette(palette);
vid.recalc_refdef := true;
end;
(*
================
VID_UpdateWindowStatus
================
*)
procedure VID_UpdateWindowStatus;
begin
window_rect.left := window_x;
window_rect.top := window_y;
window_rect.right := window_x + window_width;
window_rect.bottom := window_y + window_height;
window_center_x := (window_rect.left + window_rect.right) div 2;
window_center_y := (window_rect.top + window_rect.bottom) div 2;
IN_UpdateClipCursor;
end;
//====================================
const
TEXTURE_EXT_STRING = 'GL_EXT_texture_object';
procedure CheckTextureExtensions;
var
tmp: PChar;
texture_ext: qboolean;
hInstGL: THandle;
begin
texture_ext := false;
(* check for texture extension *)
tmp := glGetString(GL_EXTENSIONS);
while tmp^ <> #0 do
begin
if strncmp(tmp, TEXTURE_EXT_STRING, strlen(TEXTURE_EXT_STRING)) = 0 then
texture_ext := true; // JVAL mayby break here ?
inc(tmp);
end;
if not texture_ext or (COM_CheckParm('-gl11') <> 0) then
begin
hInstGL := LoadLibrary('opengl32.dll');
if hInstGL = 0 then
Sys_Error('Couldn''t load opengl32.dll'#10);
bindTexFunc := GetProcAddress(hInstGL, 'glBindTexture');
if not Assigned(bindTexFunc) then
Sys_Error('No texture objects!');
exit;
end;
(* load library and get procedure adresses for texture extension API *)
bindTexFunc := wglGetProcAddress('glBindTextureEXT');
if not Assigned(bindTexFunc) then
begin
Sys_Error('GetProcAddress for BindTextureEXT failed');
exit;
end;
end;
procedure CheckArrayExtensions;
var
tmp: PChar;
begin
(* check for texture extension *)
tmp := glGetString(GL_EXTENSIONS);
while tmp^ <> #0 do
begin
if strncmp(tmp, 'GL_EXT_vertex_array', strlen('GL_EXT_vertex_array')) = 0 then
begin
glArrayElementEXT := wglGetProcAddress('glArrayElementEXT');
glColorPointerEXT := wglGetProcAddress('glColorPointerEXT');
glTexCoordPointerEXT := wglGetProcAddress('glTexCoordPointerEXT');
glVertexPointerEXT := wglGetProcAddress('glVertexPointerEXT');
if not Assigned(glArrayElementEXT) or
not Assigned(glColorPointerEXT) or
not Assigned(glTexCoordPointerEXT) or
not Assigned(glVertexPointerEXT) then
Sys_Error('GetProcAddress for vertex extension failed');
exit;
end;
inc(tmp);
end;
Sys_Error('Vertex array extension not present');
end;
procedure CheckMultiTextureExtensions;
begin
if (strstr(str_gl_extensions, 'GL_SGIS_multitexture') <> nil) and (COM_CheckParm('-nomtex') = 0) then
begin
Con_Printf('Multitexture extensions found.'#10);
qglMTexCoord2fSGIS := wglGetProcAddress('glMTexCoord2fSGIS');
qglSelectTextureSGIS := wglGetProcAddress('glSelectTextureSGIS');
gl_mtexable := true;
end;
end;
(*
===============
GL_Init
===============
*)
procedure GL_Init;
begin
str_gl_vendor := glGetString(GL_VENDOR);
Con_Printf('GL_VENDOR: %s'#10, [str_gl_vendor]);
str_gl_renderer := glGetString(GL_RENDERER);
Con_Printf('GL_RENDERER: %s'#10, [str_gl_renderer]);
str_gl_version := glGetString(GL_VERSION);
Con_Printf('GL_VERSION: %s'#10, [str_gl_version]);
str_gl_extensions := glGetString(GL_EXTENSIONS);
Con_Printf('GL_EXTENSIONS: %s'#10, [str_gl_extensions]);
// Con_Printf ("%s %s\n", gl_renderer, gl_version);
if strncmp(str_gl_renderer, 'PowerVR', 7) = 0 then // JVAL SOS was strnicmp
fullsbardraw := true;
if strncmp(str_gl_renderer, 'Permedia', 8) = 0 then // JVAL SOS was strnicmp
isPermedia := true;
CheckTextureExtensions;
CheckMultiTextureExtensions;
glClearColor(1, 0, 0, 0);
glCullFace(GL_FRONT);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.666);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glShadeModel(GL_FLAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
GL_InitSky;
end;
(*
=================
GL_BeginRendering
=================
*)
procedure GL_BeginRendering(x, y: PInteger; width, height: PInteger);
begin
// extern cvar_t gl_clear;
x^ := 0;
y^ := 0;
width^ := WindowRect.right - WindowRect.left;
height^ := WindowRect.bottom - WindowRect.top;
end;
procedure GL_EndRendering;
begin
if not scr_skipupdate or block_drawing then
SwapBuffers(maindc);
// handle the mouse state when windowed if that's changed
if modestate = MS_WINDOWED then
begin
if _windowed_mouse.value = 0 then
begin
if windowed_mouse then
begin
IN_DeactivateMouse;
IN_ShowMouse;
windowed_mouse := false;
end;
end
else
begin
windowed_mouse := true;
if (key_dest = key_game) and not mouseactive and ActiveApp then
begin
IN_ActivateMouse;
IN_HideMouse;
end
else if mouseactive and (key_dest <> key_game) then
begin
IN_DeactivateMouse;
IN_ShowMouse;
end;
end;
end;
if fullsbardraw then
Sbar_Changed;
end;
procedure VID_SetPalette(palette: PByteArray);
var
pal: PByteArray;
r, g, b: byte;
v: unsigned;
r1, g1, b1: integer;
j, k, l: integer;
i: unsigned_short;
table: Punsigned;
begin
//
// 8 8 8 encoding
//
pal := palette;
table := @d_8to24table[0];
for i := 0 to 255 do
begin
r := pal[0];
g := pal[1];
b := pal[2];
pal := @pal[3];
table^ := (255 shl 24) + (r) + (g shl 8) + (b shl 16);
inc(table);
end;
d_8to24table[255] := d_8to24table[255] and $FFFFFF; // 255 is transparent
// JACK: 3D distance calcs - k is last closest, l is the distance.
// FIXME: Precalculate this and cache to disk.
for i := 0 to (1 shl 15) - 1 do
begin
(* Maps
000000000000000
000000000011111 = Red = 0x1F
000001111100000 = Blue = 0x03E0
111110000000000 = Grn = 0x7C00
*)
r := ((i and $001F) shl 3) + 4;
g := ((i and $03E0) shr 2) + 4;
b := ((i and $7C00) shr 7) + 4;
pal := PByteArray(@d_8to24table[0]);
k := 0;
l := 10000 * 10000;
for v := 0 to 255 do
begin
r1 := r - pal[0];
g1 := g - pal[1];
b1 := b - pal[2];
j := (r1 * r1) + (g1 * g1) + (b1 * b1);
if j < l then
begin
k := v;
l := j;
end;
pal := @pal[4];
end;
d_15to8table[i] := k;
end;
end;
procedure VID_SetDefaultMode;
begin
IN_DeactivateMouse;
end;
procedure VID_Shutdown;
var
hRC: HGLRC;
DC: HDC;
NULLMOD: DEVMODE;
begin
if vid_initialized then
begin
vid_canalttab := false;
hRC := wglGetCurrentContext;
DC := wglGetCurrentDC;
wglMakeCurrent(0, 0);
if hRC <> 0 then
wglDeleteContext(hRC);
if (DC <> 0) and (dibwindow <> 0) then
ReleaseDC(dibwindow, DC);
if modestate = MS_FULLDIB then
begin
ZeroMemory(@NULLMOD, SizeOf(NULLMOD));
ChangeDisplaySettings(NULLMOD, 0);
end;
if (maindc <> 0) and (dibwindow <> 0) then
ReleaseDC(dibwindow, maindc);
AppActivate(false, false);
end;
end;
//==========================================================================
function bSetupPixelFormat(DC: HDC): BOOL;
var
pfd: PIXELFORMATDESCRIPTOR;
pixelformat: integer;
begin
with pfd do
begin
nSize := sizeof(PIXELFORMATDESCRIPTOR); // size of this pfd
nVersion := 1; // version number
dwFlags := PFD_DRAW_TO_WINDOW or // support window
PFD_SUPPORT_OPENGL or // support OpenGL
PFD_DOUBLEBUFFER; // double buffered
iPixelType := PFD_TYPE_RGBA; // RGBA type
cColorBits := 24; // 24-bit color depth
cRedBits := 0; // color bits ignored
cRedShift := 0;
cGreenBits := 0;
cGreenShift := 0;
cBlueBits := 0;
cBlueShift := 0;
cAlphaBits := 0; // no alpha buffer
cAlphaShift := 0; // shift bit ignored
cAccumBits := 0; // no accumulation buffer
cAccumRedBits := 0; // accum bits ignored
cAccumGreenBits := 0;
cAccumBlueBits := 0;
cAccumAlphaBits := 0;
cDepthBits := 32; // 32-bit z-buffer
cStencilBits := 0; // no stencil buffer
cAuxBuffers := 0; // no auxiliary buffer
iLayerType := PFD_MAIN_PLANE; // main layer
bReserved := 0; // reserved
dwLayerMask := 0; // layer masks ignored
dwVisibleMask := 0;
dwDamageMask := 0;
end;
pixelformat := ChoosePixelFormat(DC, @pfd);
if pixelformat = 0 then
begin
MessageBox(0, 'ChoosePixelFormat failed', 'Error', MB_OK);
result := false;
exit;
end;
if not SetPixelFormat(DC, pixelformat, @pfd) then
begin
MessageBox(0, 'SetPixelFormat failed', 'Error', MB_OK); // JVAL mayby other outproc not messagebox?
result := false;
exit;
end;
result := true;
end;
var
scantokey: array[0..127] of byte = (
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
0, 27, Ord('1'), Ord('2'), Ord('3'), Ord('4'), Ord('5'), Ord('6'),
Ord('7'), Ord('8'), Ord('9'), Ord('0'), Ord('-'), Ord('='), K_BACKSPACE, 9, // 0
Ord('q'), Ord('w'), Ord('e'), Ord('r'), Ord('t'), Ord('y'), Ord('u'), Ord('i'),
Ord('o'), Ord('p'), Ord('['), Ord(']'), 13, K_CTRL, Ord('a'), Ord('s'), // 1
Ord('d'), Ord('f'), Ord('g'), Ord('h'), Ord('j'), Ord('k'), Ord('l'), Ord(';'),
Ord(''''), Ord('`'), K_SHIFT, Ord('\'), Ord('z'), Ord('x'), Ord('c'), Ord('v'), // 2
Ord('b'), Ord('n'), Ord('m'), Ord(')'), Ord('.'), Ord('/'), K_SHIFT, Ord('*'),
K_ALT, Ord(' '), 0, K_F1, K_F2, K_F3, K_F4, K_F5, // 3
K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE, 0, K_HOME,
K_UPARROW, K_PGUP, Ord('-'), K_LEFTARROW, Ord('5'), K_RIGHTARROW, Ord('+'), K_END, //4
K_DOWNARROW, K_PGDN, K_INS, K_DEL, 0, 0, 0, K_F11,
K_F12, 0, 0, 0, 0, 0, 0, 0, // 5
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, // 6
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 // 7
);
shiftscantokey: array[0..127] of byte = (
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
0, 27, Ord('!'), Ord('@'), Ord('#'), Ord('$'), Ord('%'), Ord('^'),
Ord('&'), Ord('*'), Ord('('), Ord(')'), Ord('_'), Ord('+'), K_BACKSPACE, 9, // 0
Ord('Q'), Ord('W'), Ord('E'), Ord('R'), Ord('T'), Ord('Y'), Ord('U'), Ord('I'),
Ord('O'), Ord('P'), Ord('{'), Ord('}'), 13, K_CTRL, Ord('A'), Ord('S'), // 1
Ord('D'), Ord('F'), Ord('G'), Ord('H'), Ord('J'), Ord('K'), Ord('L'), Ord(':'),
Ord('"'), Ord('~'), K_SHIFT, Ord('|'), Ord('Z'), Ord('X'), Ord('C'), Ord('V'), // 2
Ord('B'), Ord('N'), Ord('M'), Ord('<'), Ord('>'), Ord('?'), K_SHIFT, Ord('*'),
K_ALT, Ord(' '), 0, K_F1, K_F2, K_F3, K_F4, K_F5, // 3
K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE, 0, K_HOME,
K_UPARROW, K_PGUP, Ord('_'), K_LEFTARROW, Ord('%'), K_RIGHTARROW, Ord('+'), K_END, //4
K_DOWNARROW, K_PGDN, K_INS, K_DEL, 0, 0, 0, K_F11,
K_F12, 0, 0, 0, 0, 0, 0, 0, // 5
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, // 6
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 // 7
);
(*
=======
MapKey
Map from windows to quake keynums
=======
*)
function MapKey(key: integer): integer;
begin
key := (key shr 16) and 255;
if key > 127 then
begin
result := 0;
exit;
end;
result := scantokey[key];
if result = 0 then
Con_DPrintf('key 0x%02x has no translation'#10, [key]); // JVAL check format string
end;
(*
===================================================================
MAIN WINDOW
===================================================================
*)
(*
================
ClearAllStates
================
*)