forked from SpiritQuaddicted/reQuiem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gl_draw.c
2233 lines (1859 loc) · 48.8 KB
/
gl_draw.c
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
/*
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.
*/
// gl_draw.c -- this is the only file outside the refresh that touches the vid buffer
#include "quakedef.h"
#ifndef RQM_SV_ONLY
int texture_extension_number = 1;
cvar_t gl_conalpha = {"gl_conalpha", "0.6", CVAR_FLAG_ARCHIVE}; // by joe
cvar_t gl_externaltextures_world = {"gl_externaltextures_world", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_externaltextures_bmodels = {"gl_externaltextures_bmodels", "1", CVAR_FLAG_ARCHIVE};
cvar_t gl_externaltextures_models = {"gl_externaltextures_models", "1", CVAR_FLAG_ARCHIVE};
qboolean OnChange_gl_consolefont (cvar_t *var, const char *string);
cvar_t gl_consolefont = {"gl_consolefont", "original", CVAR_FLAG_ARCHIVE, OnChange_gl_consolefont};
qboolean OnChange_gl_smoothfont (cvar_t *var, const char *string);
cvar_t gl_smoothfont = {"gl_smoothfont", "0", CVAR_FLAG_ARCHIVE, OnChange_gl_smoothfont};
qboolean OnChange_gl_crosshairimage (cvar_t *var, const char *string);
cvar_t gl_crosshairimage = {"crosshairimage", "", CVAR_FLAG_ARCHIVE, OnChange_gl_crosshairimage};
cvar_t gl_crosshairalpha = {"crosshairalpha", "1", CVAR_FLAG_ARCHIVE};
cvar_t crosshair = {"crosshair", "1", CVAR_FLAG_ARCHIVE}; // JDH: default was 2
cvar_t crosshaircolor = {"crosshaircolor", "10", CVAR_FLAG_ARCHIVE}; // JDH: changed default from red (79) to light grey
cvar_t crosshairsize = {"crosshairsize", "1", CVAR_FLAG_ARCHIVE};
cvar_t cl_crossx = {"cl_crossx", "0", CVAR_FLAG_ARCHIVE};
cvar_t cl_crossy = {"cl_crossy", "0", CVAR_FLAG_ARCHIVE};
//byte *draw_chars; // 8*8 graphic characters
mpic_t *draw_backtile;
mpic_t *draw_disc;
#define STAT_MINUS 10 // num frame for '-' stats digit
mpic_t *draw_bignums[2][STAT_MINUS+1]; // from sbar.c
mpic_t *draw_bigcolon, *draw_bigslash; // ditto
#ifdef HEXEN2_SUPPORT
#define MAX_DISC 18
extern int loading_stage;
mpic_t *draw_disc_H2[MAX_DISC];
int char_smalltexture;
char BigCharWidth[27][27];
#endif
//int translate_texture;
int char_texture;
int char_texture_bright;
float charset_hspacing, charset_vspacing; // distance from one char to the next, as a
// multiple of character's width or height
// JDH: some extra characters for menu & console:
//int char_texture2;
//int char_menufonttexture = 0;
static char MenuFontWidths[64][64];
extern cvar_t crosshair, cl_crossx, cl_crossy, crosshaircolor, crosshairsize;
mpic_t crosshairpic;
static qboolean crosshairimage_loaded = false;
//mpic_t conback_data;
//mpic_t *conback = &conback_data;
mpic_t draw_conback;
mpic_t draw_menufont;
int gl_lightmap_format = 3, gl_solid_format = 3, gl_alpha_format = 4;
#define NUMCROSSHAIRS 6
int crosshairtextures[NUMCROSSHAIRS];
// JDH: made these palette-independent (0 --> transparent, 1 to 255 --> greyscale)
static byte crosshairdata[NUMCROSSHAIRS][64] =
{
{ 0x00, 0x00, 0x00, 0xEF, 0xEF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xEF, 0xCF, 0x20, 0x00, 0x00,
0x00, 0xEF, 0xEF, 0xCF, 0xEF, 0xCF, 0xEF, 0x00,
0x00, 0x00, 0x20, 0xEF, 0xCF, 0x20, 0x20, 0x20,
0x00, 0x00, 0x00, 0xDF, 0xFF, 0x20, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00,
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF
},
{ 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00,
0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00,
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}
};
//=============================================================================
/* Support Routines */
typedef struct cachepic_s
{
char name[MAX_QPATH];
mpic_t pic;
} cachepic_t;
#define MAX_CACHED_PICS 256 // JDH: was 128
cachepic_t cachepics[MAX_CACHED_PICS];
int numcachepics;
/*
#ifdef HEXEN2_SUPPORT
byte *menuplyr_pixels[NUM_CLASSES];
#else
byte *menuplyr_pixels[1];
#endif
*/
//int pic_texels;
//int pic_count;
mpic_t * Draw_FindCachePic (const char *filepath)
{
cachepic_t *pic;
int i;
for (pic = cachepics, i = 0 ; i < numcachepics ; pic++, i++)
if (!strcmp(filepath, pic->name))
return &pic->pic;
return NULL;
}
/*
================
Draw_AddCachePic
================
*/
mpic_t *Draw_AddCachePic (const char *filepath, byte *data, int width, int height)
{
// int player_idx = -1;
cachepic_t *pic;
mpic_t *pic_24bit;
if (numcachepics == MAX_CACHED_PICS)
Sys_Error ("numcachepics == MAX_CACHED_PICS");
/*
// HACK HACK HACK --- we need to keep the bytes for
// the translatable player picture just for the menu
// configuration dialog
#ifdef HEXEN2_SUPPORT
if (hexen2)
{
if (COM_FilenamesEqual (filepath, "gfx/menu/netp1.lmp"))
player_idx = 0;
else if (COM_FilenamesEqual (filepath, "gfx/menu/netp2.lmp"))
player_idx = 1;
else if (COM_FilenamesEqual (filepath, "gfx/menu/netp3.lmp"))
player_idx = 2;
else if (COM_FilenamesEqual (filepath, "gfx/menu/netp4.lmp"))
player_idx = 3;
else if (COM_FilenamesEqual (filepath, "gfx/menu/netp5.lmp"))
player_idx = 4;
}
else
#endif
if (COM_FilenamesEqual(filepath, "gfx/menuplyr.lmp"))
{
player_idx = 0;
}
if (player_idx >= 0)
{
// assert (width*height <= sizeof(menuplyr_pixels[player_idx]));
if (menuplyr_pixels[player_idx])
free (menuplyr_pixels[player_idx]);
menuplyr_pixels[player_idx] = malloc (width*height);
memcpy (menuplyr_pixels[player_idx], data, width*height);
}
*/
pic = &cachepics[numcachepics++];
Q_strcpy (pic->name, filepath, sizeof(pic->name));
if (!no24bit)
{
char *name, path[MAX_QPATH];
name = COM_SkipPath (filepath);
Q_strncpy (path, sizeof(path), filepath, name-filepath);
//path[name-filepath] = 0;
pic_24bit = GL_LoadPicImage (path, name, NULL, TEX_ALPHA | TEX_NOTILE, 0);
if (pic_24bit)
{
//memcpy (&pic->pic.texnum, &pic_24bit->texnum, sizeof(mpic_t) - 8);
pic->pic = *pic_24bit;
}
}
else pic_24bit = NULL;
pic->pic.width = width;
pic->pic.height = height;
if (!pic_24bit)
GL_LoadPicTexture (filepath, &pic->pic, data, TEX_ALPHA | TEX_NOTILE, 1);
return &pic->pic;
}
/*
================
Draw_GetCachePic
(JDH: originally named Draw_CachePic)
================
*/
mpic_t *Draw_GetCachePic (const char *filepath, qboolean crash)
{
mpic_t *pic;
qpic_t *dat;
pic = Draw_FindCachePic (filepath);
if (pic)
return pic;
if (!(dat = (qpic_t *) COM_LoadTempFile (filepath, 0)))
{
if (crash)
Sys_Error ("Draw_GetCachePic: failed to load %s", filepath);
return NULL;
}
SwapPic (dat);
return Draw_AddCachePic (filepath, dat->data, dat->width, dat->height);
}
/*
===============
Draw_CopyPicToPic
===============
*/
void Draw_CopyPicToPic (const qpic_t *pic_src, qpic_t *pic_dest, int x, int y)
{
int width, height, i;
const byte *src;
byte *dest;
src = pic_src->data;
width = pic_src->width;
height = pic_src->height;
if (x < 0)
{
width += x;
src -= x;
x = 0;
}
if (y < 0)
{
height += y;
src -= y*pic_src->width;
y = 0;
}
width = min(width, pic_dest->width - x);
height = min(height, pic_dest->height - y);
dest = pic_dest->data + y*pic_dest->width + x;
for (i = 0; i < height; i++)
{
memcpy (dest, src, width);
dest += pic_dest->width;
src += pic_src->width;
}
}
/*void Draw_CharToConback (int num, byte *dest)
{
int row, col, drawline, x;
byte *source;
row = num >> 4;
col = num & 15;
source = draw_chars + (row<<10) + (col<<3);
drawline = 8;
while (drawline--)
{
for (x=0 ; x<8 ; x++)
if (source[x] != 255)
dest[x] = 0x60 + source[x];
source += 128;
dest += 320;
}
}
*/
void Draw_InitConback (void)
{
qpic_t *cb;
int start;
mpic_t *pic_24bit;
const char *path;
#if 0
int x, y;
byte *dest;
char ver[40];
#endif
start = Hunk_LowMark ();
#ifdef HEXEN2_SUPPORT
if (hexen2)
path = "gfx/menu/";
else
#endif
path = "gfx/";
cb = (qpic_t *) COM_LoadHunkFile (va ("%sconback.lmp", path), 0);
if (!cb)
Sys_Error (va("Couldn't load %sconback.lmp", path));
SwapPic (cb);
/*****JDH******/
// if (cb->width != 320 || cb->height != 200)
// Sys_Error ("Draw_InitConback: conback.lmp size is not 320x200");
/*****JDH******/
/*
#if 0 // hack the version number directly into the pic
sprintf (ver, "j0e-%4.2fbeta", (float)JOEQUAKE_VERSION);
dest = cb->data + 320*186 + 320 - 11 - 8*strlen(ver);
y = strlen(ver);
for (x=0 ; x<y ; x++)
Draw_CharToConback (ver[x], dest + (x<<3));
#endif
*/
if ((pic_24bit = GL_LoadPicImage(path, "conback", "conback", 0, com_filepath->dir_level)))
{
// memcpy (&conback->texnum, &pic_24bit->texnum, sizeof(mpic_t) - 8); // this line bothers me...
// memcpy (&draw_conback, pic_24bit, sizeof(mpic_t));
draw_conback = *pic_24bit;
}
else
{
draw_conback.width = cb->width;
draw_conback.height = cb->height;
GL_LoadPicTexture ("conback", &draw_conback, cb->data, 0, 1);
}
draw_conback.width = vid.conwidth;
draw_conback.height = vid.conheight;
// free loaded console
Hunk_FreeToLowMark (start);
}
/*
===============
GL_LoadCharsetImage
===============
*/
int GL_LoadCharsetImage (const char *filename, const char *identifier)
{
int i, j, texnum, image_size;
byte *data, *buf, *dest, *src;
qboolean transparent = false;
if (no24bit)
return 0;
if (!(data = GL_LoadImage("textures/charsets/", filename, 0, 0)))
return 0;
if (!identifier)
identifier = filename;
image_size = image_width * image_height;
for (j=0 ; j<image_size ; j++)
{
if (((((unsigned *)data)[j] >> 24) & 0xFF) < 255)
{
transparent = true;
break;
}
}
if (!transparent)
{
for (i=0 ; i < image_width * image_height ; i++)
{
if (data[i*4] == data[0] && data[i*4+1] == data[1] && data[i*4+2] == data[2])
data[i*4+3] = 0;
}
}
/*buf = dest = Q_calloc (image_size * 2, 4);
src = data;
for (i=0 ; i<16 ; i++)
{
memcpy (dest, src, image_size >> 2);
src += image_size >> 2;
dest += image_size >> 1;
}
texnum = GL_LoadTexture (identifier, image_width, image_height * 2, buf, TEX_ALPHA, 4);
if (texnum)
{
charset_hspacing = 1.0;
charset_vspacing = 2.0;
}
free (buf);
free (data);*/
texnum = GL_LoadTexture (identifier, image_width, image_height, data, TEX_ALPHA, 4);
free (data);
return texnum;
}
void GL_SetFontFilter (float filter)
{
// assumes charset texture is currently bound
if (filter)
{
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else
{
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
}
qboolean OnChange_gl_smoothfont (cvar_t *var, const char *string)
{
float newval = Q_atof (string);
if (char_texture)
{
GL_Bind (char_texture);
GL_SetFontFilter (newval);
}
if (char_texture_bright)
{
GL_Bind (char_texture_bright);
GL_SetFontFilter (newval);
}
M_OnChange_gl_smoothfont (newval);
return false; // allow change
}
static qboolean Draw_LoadConchars (const byte *data, int width, int height, int rows, int cols)
{
int charwidth, charheight, newsize, i, j;
const byte *src;
byte *buf, *dest;
unsigned *buf32, r, g, b;
charwidth = width/cols;
charheight = height/rows;
/* if ((width*2 <= gl_max_size.value) && (height*2 <= gl_max_size.value))
{
// Double the texture's width and height, leaving empty space between chars
// so that they don't stumble on each other because of texture smoothing.
// This hack costs us an extra 192K of GL texture memory
newsize = width*height*4;
buf = Q_malloc (newsize);
memset (buf, 255, newsize);
src = data;
dest = buf;
for (i=0 ; i<rows ; i++)
{
for (j = 0; j < (width/charwidth)*charheight; j++)
{
memcpy (dest, src, charwidth);
dest[charwidth] = dest[charwidth-1]; // duplicate last pixel of each row in char
src += charwidth;
dest += charwidth*2;
dest[-1] = *src; // precede first pixel of each row in char with duplicate
}
memcpy (dest, dest-width*2, width*2); // JDH: duplicate bottom row of pixels
dest += width*2*charheight;
}
width *= 2;
height *= 2;
charset_hspacing = charset_vspacing = 2.0;
}
else */
{
newsize = width*height;
buf = (byte *) data;
charset_hspacing = charset_vspacing = 1.0;
}
char_texture = GL_LoadTexture ("pic:charset", width, height, buf, TEX_ALPHA | TEX_NOFILTER, 1);
// TEX_NOFILTER since they obey gl_smoothfont cvar, not gl_texturemode
GL_SetFontFilter (gl_smoothfont.value);
// JDH: create a brighter version for auto-complete text (colors get inverted when drawn)
buf32 = Q_malloc (newsize*4); // 32-bit color
for (i = 0; i < newsize; i++)
{
r = ((d_8to24table[buf[i]] & 0x000000FF) * 1.5);
r = min(r, 255);
g = (((d_8to24table[buf[i]] & 0x0000FF00) >> 8) * 1.5);
g = min(g, 255);
b = (((d_8to24table[buf[i]] & 0x00FF0000) >> 16) * 1.5);
b = min(b, 255);
buf32[i] = buf[i] == 255 ? 0 : 0xFF000000;
buf32[i] |= ((b << 16) | (g << 8) | r);
}
char_texture_bright = GL_LoadTexture ("pic:charset2", width, height, buf32, TEX_ALPHA | TEX_NOFILTER, 4);
GL_SetFontFilter (gl_smoothfont.value);
free (buf32);
if (buf != data)
free (buf);
return true;
}
#define CONCHARS_NUMROWS 16
#define CONCHARS_NUMCOLS 16
#ifdef HEXEN2_SUPPORT
# define CONCHARS_NUMROWS_H2 16
# define CONCHARS_NUMCOLS_H2 32
#endif
qboolean Draw_LoadCharsetData (const char *name, byte *data, int size)
{
int i, width, height, rows, cols, texnum;
if (data && !Q_strcasecmp(name, gl_consolefont.defaultvalue))
{
for (i=0 ; i<size ; i++)
if (data[i] == 0)
data[i] = 255; // proper transparent color
#ifdef HEXEN2_SUPPORT
if (hexen2)
{
height = sqrt(size/2);
width = 2*height;
rows = CONCHARS_NUMROWS_H2;
cols = CONCHARS_NUMCOLS_H2;
// char_texture = GL_LoadTexture ("charset", width, height, data, TEX_ALPHA, 1);
}
else
#endif
{
width = height = sqrt(size);
rows = CONCHARS_NUMROWS;
cols = CONCHARS_NUMCOLS;
}
return Draw_LoadConchars (data, width, height, rows, cols);
}
texnum = GL_LoadCharsetImage (name, "pic:charset");
if (!texnum)
{
Con_Printf ("Couldn't load charset \"%s\"\n", name);
return false;
}
char_texture = texnum;
return true;
}
qboolean Draw_LoadCharset (const char *name)
{
byte *data;
int size;
qboolean result;
#ifdef HEXEN2_SUPPORT
if (hexen2)
{
data = COM_LoadMallocFile ("gfx/menu/conchars.lmp", 0);
if (data)
{
result = Draw_LoadCharsetData (name, data, com_filesize);
free (data);
}
}
else
#endif
{
data = W_GetLumpByName ("conchars", &size);
result = Draw_LoadCharsetData (name, data, size);
}
return result;
}
qboolean OnChange_gl_consolefont (cvar_t *var, const char *string)
{
return !Draw_LoadCharset (string);
}
void Draw_LoadCharset_f (cmd_source_t src)
{
switch (Cmd_Argc())
{
case 1:
Con_Printf ("Current charset is \"%s\"\n", gl_consolefont.string);
break;
case 2:
Cvar_SetDirect (&gl_consolefont, Cmd_Argv(1));
break;
default:
Con_Printf ("Usage: %s <charset>\n", Cmd_Argv(0));
}
}
void Draw_InitCharset (void)
{
int size, i, j;
qpic_t *pic;
mpic_t *pic_24bit;
byte *data;
Draw_LoadCharset (gl_consolefont.string);
#ifdef HEXEN2_SUPPORT
if (hexen2)
{
data = W_GetLumpByName ("tinyfont", &size);
if (data)
{
for (i=0 ; i<128*32 ; i++)
if (data[i] == 0)
data[i] = 255; // proper transparent color
// now turn them into textures
char_smalltexture = GL_LoadTexture ("smallcharset", 128, 32, data, TEX_ALPHA, 1);
}
else char_smalltexture = 0;
pic = (qpic_t *) COM_LoadTempFile ("gfx/menu/bigfont2.lmp", 0);
if (pic)
{
SwapPic (pic);
for (i=0 ; i<pic->width*pic->height ; i++)
if (pic->data[i] == 0)
pic->data[i] = 255; // proper transparent color
draw_menufont.width = pic->width;
draw_menufont.height = pic->height;
GL_LoadPicTexture ("menufont", &draw_menufont, pic->data, TEX_ALPHA, 1);
//char_menufonttexture = GL_LoadTexture ("menufont", pic->width, pic->height, pic->data, TEX_ALPHA, 1);
}
else memset (&draw_menufont, 0, sizeof(draw_menufont));
// Load the table of character widths:
COM_LoadStackFile ("gfx/menu/fontsize.lmp", BigCharWidth, sizeof(BigCharWidth), 0);
}
else
#endif
{
// Draw_LoadCharset (gl_consolefont.string, width, height);
if (!char_texture)
Cvar_SetDirect (&gl_consolefont, "original");
if ((pic_24bit = GL_LoadPicImage ("gfx/", "mcharset", "menufont", TEX_ALPHA, 0)))
{
draw_menufont = *pic_24bit;
draw_menufont.width = DRAW_BIGCHARWIDTH*8; // so each char occupies 24 pixels onscreen
draw_menufont.height = DRAW_BIGCHARWIDTH*8;
for (i = 0; i < 64; i++)
for (j = 0; j < 64; j++)
MenuFontWidths[i][j] = DRAW_BIGCHARWIDTH;
}
else
{
pic = (qpic_t *) COM_LoadTempFile ("gfx/menufont.lmp", 0);
if (!pic)
pic = (qpic_t *) COM_LoadTempFile ("gfx/bigfont.lmp", 0);
if (pic)
{
SwapPic (pic);
for (i=0 ; i<pic->width*pic->height ; i++)
if (pic->data[i] == 254)
pic->data[i] = 255; // convert white bounding boxes to transparent (TEMP FIX!!)
draw_menufont.width = pic->width;
draw_menufont.height = pic->height;
GL_LoadPicTexture ("menufont", &draw_menufont, pic->data, TEX_ALPHA, 1);
// char_menufonttexture = GL_LoadTexture ("menufont", pic->width, pic->height, pic->data, TEX_ALPHA, 1);
// Load the table of character widths:
COM_LoadStackFile ("gfx/fontsize.lmp", MenuFontWidths, sizeof(MenuFontWidths), 0);
for (i = 0; i < 64; i++)
for (j = 0; j < 64; j++)
if (MenuFontWidths[i][j] == 0)
MenuFontWidths[i][j] = pic->width/10.0; // **TEMP** (until I finish font)
}
else memset (&draw_menufont, 0, sizeof(draw_menufont));
}
}
if (!char_texture)
Sys_Error ("Draw_InitCharset: Couldn't load charset");
// JDH: load extra characters
/* pic = (qpic_t *) COM_LoadTempFile ("gfx/conchars2.lmp", 0);
if (pic)
{
SwapPic (pic);
for (i=0 ; i<pic->width*pic->height ; i++)
if (pic->data[i] == 0)
pic->data[i] = 255; // proper transparent color
char_texture2 = GL_LoadTexture ("conchars2", pic->width, pic->height, pic->data, TEX_ALPHA, 1);
}
*/
}
static const char *crosshair_pathlist[3] = {"crosshairs/", "textures/crosshairs/", NULL};
qboolean OnChange_gl_crosshairimage (cvar_t *var, const char *string)
{
mpic_t *pic;
const char *namelist[2];
if (!string[0])
{
crosshairimage_loaded = false;
return false;
}
namelist[0] = string;
namelist[1] = NULL;
if (!(pic = GL_LoadPicImage_MultiSource (crosshair_pathlist, namelist, "crosshair", TEX_ALPHA | TEX_NOTILE, 0)))
{
crosshairimage_loaded = false;
if (key_dest != key_menu)
Con_Printf ("Couldn't load crosshair \"%s\"\n", string);
return false;
}
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
crosshairpic = *pic;
crosshairimage_loaded = true;
return false;
}
/*
===============
Draw_LoadWadPics
===============
*/
void Draw_LoadWadPics (void)
{
#ifdef HEXEN2_SUPPORT
int i;
// get the other pics we need
if (hexen2)
{
for (i = 0; i < MAX_DISC; i++)
{
draw_disc_H2[i] = Draw_GetCachePic (va ("gfx/menu/skull%d.lmp", i), true);
}
draw_disc = draw_disc_H2[0]; // just in case - but draw_disc shouldn't get used
draw_backtile = Draw_GetCachePic ("gfx/menu/backtile.lmp", true);
}
else
#endif
{
#ifdef HEXEN2_SUPPORT
for (i = 0; i < MAX_DISC; i++)
{
draw_disc_H2[i] = NULL;
}
#endif
draw_disc = Draw_PicFromWad ("disc");
draw_backtile = Draw_PicFromWad ("backtile");
}
for (i = 0; i < STAT_MINUS; i++)
{
draw_bignums[0][i] = Draw_PicFromWad (va("num_%i", i));
}
draw_bignums[0][STAT_MINUS] = Draw_PicFromWad ("num_minus");
draw_bigcolon = Draw_PicFromWad ("num_colon");
draw_bigslash = Draw_PicFromWad ("num_slash");
#ifdef HEXEN2_SUPPORT
if (!hexen2)
{
#endif
for (i=0 ; i<STAT_MINUS ; i++)
{
draw_bignums[1][i] = Draw_PicFromWad (va("anum_%i", i));
}
draw_bignums[1][STAT_MINUS] = Draw_PicFromWad ("anum_minus");
}
Sbar_LoadWadPics ();
SCR_LoadWadPics ();
}
/*
==================
Draw_ReloadWadFile
==================
*/
void Draw_ReloadWadFile (void)
{
int i;
if (cls.state == ca_dedicated)
return;
if (!W_LoadWadFile ("gfx.wad"))
return;
draw_disc = NULL;
draw_backtile = NULL;
#ifdef HEXEN2_SUPPORT
for (i = 0; i < MAX_DISC; i++)
{
draw_disc_H2[i] = NULL;
}
#endif
// JDH: moved big numbers here from sbar.c
for (i = 0; i <= STAT_MINUS; i++)
{
draw_bignums[0][i] = draw_bignums[1][i] = NULL;
}
draw_bigcolon = draw_bigslash = NULL;
SCR_ClearWadPics ();
Sbar_ClearWadPics ();
Draw_LoadWadPics ();
Draw_InitCharset ();
Draw_InitConback ();
}
/*
===============
Draw_Init
===============
*/
void Draw_Init (void)
{
int i, j;
unsigned data24[8*8];
#define MAKEGREY(c) (0xFF000000 | ((int)(c) << 16) | ((int)(c) << 8) | (c))
Cmd_AddCommand ("loadcharset", Draw_LoadCharset_f, 0);
Cvar_RegisterBool (&gl_externaltextures_world);
Cvar_RegisterBool (&gl_externaltextures_bmodels);
Cvar_RegisterBool (&gl_externaltextures_models);
Cvar_RegisterString (&gl_consolefont);
Cvar_RegisterFloat (&gl_conalpha, 0, 1);
Cvar_RegisterBool (&gl_smoothfont);
Cvar_RegisterFloat (&gl_crosshairalpha, 0, 1);
Cvar_RegisterString (&gl_crosshairimage);
Cvar_RegisterInt (&crosshair, 0, NUMCROSSHAIRS+1);
Cvar_RegisterString (&crosshaircolor);
Cvar_RegisterFloat (&crosshairsize, 0.5, 4);
Cvar_RegisterInt (&cl_crossx, -(int)vid.width/8, vid.width/8);
Cvar_RegisterInt (&cl_crossy, -(int)vid.height/8, vid.height/8);
Cmd_AddLegacyCommand ("con_alpha", gl_conalpha.name);
GL_TextureInit ();
// load the console background and the charset by hand, because we need to write the version
// string into the background before turning it into a texture
Draw_InitCharset ();
Draw_InitConback ();
/*
// save a texture slot for translated picture
translate_texture = texture_extension_number++; --> to M_Init
#ifdef HEXEN2_SUPPORT
texture_extension_number += NUM_CLASSES-1;
#endif
*/
// save slots for scraps
// scrap_texnum = texture_extension_number; // --> to GL_TextureInit
// texture_extension_number += MAX_SCRAPS;
// Load the crosshair pics
for (i=0 ; i<NUMCROSSHAIRS ; i++)
{
for (j = 0; j < 8*8; j++)
data24[j] = crosshairdata[i][j] ? MAKEGREY(crosshairdata[i][j]) : 0;
crosshairtextures[i] = GL_LoadTexture ("", 8, 8, (byte *)data24, TEX_ALPHA | TEX_NOTILE, 4);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
Draw_LoadWadPics ();
}
/*