-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathgl_draw.c
More file actions
2378 lines (2012 loc) · 52.1 KB
/
gl_draw.c
File metadata and controls
2378 lines (2012 loc) · 52.1 KB
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.
*/
// draw.c -- this is the only file outside the refresh that touches the
// vid buffer
#include "../../../nzportable_def.h"
#define GL_COLOR_INDEX8_EXT 0x80E5
#pragma GCC diagnostic ignored "-Wstringop-overflow="
extern unsigned char d_15to8table[65536];
cvar_t gl_nobind = {"gl_nobind", "0"};
cvar_t gl_max_size = {"gl_max_size", "1024"};
cvar_t gl_picmip = {"gl_picmip", "0"};
byte *draw_chars; // 8*8 graphic characters
qpic_t *sniper_scope;
qpic_t *draw_backtile;
int translate_texture;
int char_texture;
typedef struct
{
int texnum;
float sl, tl, sh, th;
} glpic_t;
byte conback_buffer[sizeof(qpic_t) + sizeof(glpic_t)];
int gl_lightmap_format = 4;
int gl_solid_format = 3;
int gl_alpha_format = 4;
int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST;
int gl_filter_max = GL_LINEAR;
int texels;
int GL_LoadPicTexture (qpic_t *pic);
//Loading Fill by Crow_bar
float loading_cur_step;
char loading_name[32];
float loading_num_step;
int loading_step;
float loading_cur_step_bk;
typedef struct
{
int texnum;
char identifier[64];
int original_width;
int original_height;
int width, height;
qboolean mipmap;
qboolean islmp;
int checksum;
// Diabolicka TGA
int bytesperpixel;
int lhcsum;
// Diabolickal end
} gltexture_t;
#define MAX_GLTEXTURES 1024
gltexture_t gltextures[MAX_GLTEXTURES];
int numgltextures;
void GL_Bind (int texnum)
{
if (gl_nobind.value)
texnum = char_texture;
if (currenttexture == texnum)
return;
currenttexture = texnum;
glBindTexture(GL_TEXTURE_2D, texnum);
}
/*
=============================================================================
scrap allocation
Allocate all the little status bar obejcts into a single texture
to crutch up stupid hardware / drivers
=============================================================================
*/
#define MAX_SCRAPS 2
#define BLOCK_WIDTH 256
#define BLOCK_HEIGHT 256
int scrap_allocated[MAX_SCRAPS][BLOCK_WIDTH];
byte scrap_texels[MAX_SCRAPS][BLOCK_WIDTH*BLOCK_HEIGHT*4];
qboolean scrap_dirty;
int scrap_texnum;
// returns a texture number and the position inside it
int Scrap_AllocBlock (int w, int h, int *x, int *y)
{
int i, j;
int best, best2;
int texnum;
for (texnum=0 ; texnum<MAX_SCRAPS ; texnum++)
{
best = BLOCK_HEIGHT;
for (i=0 ; i<BLOCK_WIDTH-w ; i++)
{
best2 = 0;
for (j=0 ; j<w ; j++)
{
if (scrap_allocated[texnum][i+j] >= best)
break;
if (scrap_allocated[texnum][i+j] > best2)
best2 = scrap_allocated[texnum][i+j];
}
if (j == w)
{ // this is a valid spot
*x = i;
*y = best = best2;
}
}
if (best + h > BLOCK_HEIGHT)
continue;
for (i=0 ; i<w ; i++)
scrap_allocated[texnum][*x + i] = best + h;
return texnum;
}
Sys_Error ("full");
return 0; // naievil -- will never be reached only for warning removal
}
int scrap_uploads;
void Scrap_Upload (void)
{
int texnum;
scrap_uploads++;
for (texnum=0 ; texnum<MAX_SCRAPS ; texnum++) {
GL_Bind(scrap_texnum + texnum);
GL_Upload8 (scrap_texels[texnum], BLOCK_WIDTH, BLOCK_HEIGHT, false, true);
}
scrap_dirty = false;
}
//=============================================================================
/* Support Routines */
typedef struct cachepic_s
{
char name[MAX_QPATH];
qpic_t pic;
byte padding[32]; // for appended glpic
} cachepic_t;
#define MAX_CACHED_PICS 128
cachepic_t menu_cachepics[MAX_CACHED_PICS];
int menu_numcachepics;
byte menuplyr_pixels[4096];
int pic_texels;
int pic_count;
/*
================
Draw_CachePic
================
*/
qpic_t *Draw_CachePic (char *path)
{
cachepic_t *pic;
int i;
qpic_t *dat;
glpic_t *gl;
char str[128];
strcpy (str, path);
for (pic=menu_cachepics, i=0 ; i<menu_numcachepics ; pic++, i++)
if (!strcmp (str, pic->name))
return &pic->pic;
if (menu_numcachepics == MAX_CACHED_PICS)
Sys_Error ("menu_numcachepics == MAX_CACHED_PICS");
menu_numcachepics++;
strcpy (pic->name, str);
//
// load the pic from disk
//
int index = loadtextureimage (str, 0, 0, qfalse, qfalse);
if(index)
{
pic->pic.width = gltextures[index].original_width;
pic->pic.height = gltextures[index].original_height;
gltextures[index].islmp = qfalse;
gl = (glpic_t *)pic->pic.data;
gl->texnum = index;
return &pic->pic;
}
dat = (qpic_t *)COM_LoadTempFile (str);
if (!dat)
{
strcat (str, ".lmp");
dat = (qpic_t *)COM_LoadTempFile (str);
if (!dat)
{
Con_Printf ("Draw_CachePic: failed to load file %s\n", str);
return NULL;
}
}
SwapPic (dat);
pic->pic.width = dat->width;
pic->pic.height = dat->height;
gl = (glpic_t *)pic->pic.data;
gl->texnum = GL_LoadPicTexture (dat);
gltextures[gl->texnum].islmp = qtrue;
return &pic->pic;
}
typedef struct
{
char *name;
int minimize, maximize;
} glmode_t;
glmode_t modes[] = {
{"GL_NEAREST", GL_NEAREST, GL_NEAREST},
{"GL_LINEAR", GL_LINEAR, GL_LINEAR},
{"GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST},
{"GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR},
{"GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST},
{"GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR}
};
/*
===============
Draw_TextureMode_f
===============
*/
void Draw_TextureMode_f (void)
{
int i;
gltexture_t *glt;
if (Cmd_Argc() == 1)
{
for (i=0 ; i< 6 ; i++)
if (gl_filter_min == modes[i].minimize)
{
Con_Printf ("%s\n", modes[i].name);
return;
}
Con_Printf ("current filter is unknown???\n");
return;
}
for (i=0 ; i< 6 ; i++)
{
if (!Q_strcasecmp (modes[i].name, Cmd_Argv(1) ) )
break;
}
if (i == 6)
{
Con_Printf ("bad filter name\n");
return;
}
gl_filter_min = modes[i].minimize;
gl_filter_max = modes[i].maximize;
// change all the existing mipmap texture objects
for (i=0, glt=gltextures ; i<numgltextures ; i++, glt++)
{
if (glt->mipmap)
{
GL_Bind (glt->texnum);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
}
}
}
// ! " # $ % & ' ( ) * _ , - . / 0
// 1 2 3 4 5 6 7 8 9 : ; < = > ? @
// A B C D E F G H I J K L M N O P
// Q R S T U V W X Y Z [ \ ] ^ _ `
// a b c d e f g h i j k l m n o p
// q r s t u v w x y z { | } ~
int font_kerningamount[96];
void InitKerningMap(void)
{
// Initialize the kerning amount as 8px for each
// char in the event we cant load the file.
for(int i = 0; i < 96; i++) {
font_kerningamount[i] = 8;
}
FILE *kerning_map = fopen(va("%s/gfx/kerning_map.txt", com_gamedir), "r");
if (kerning_map == NULL) {
return;
}
char buffer[1024];
if (fgets(buffer, sizeof(buffer), kerning_map) != NULL) {
char *token = strtok(buffer, ",");
int i = 0;
while (token != NULL && i < 96) {
font_kerningamount[i++] = atoi(token);
token = strtok(NULL, ",");
}
}
fclose(kerning_map);
}
/*
===============
Draw_Init
===============
*/
void Draw_Init (void)
{
int start;
numgltextures = 0;
Cvar_RegisterVariable (&gl_nobind);
Cvar_RegisterVariable (&gl_max_size);
Cvar_RegisterVariable (&gl_picmip);
if (!new3ds_flag) {
//Cvar_SetValue("gl_picmip", 1);
Cvar_Set ("gl_max_size", "256");
}
Cmd_AddCommand ("gl_texturemode", &Draw_TextureMode_f);
// now turn them into textures
char_texture = loadtextureimage ("gfx/charset", 0, 0, false, false);
if (char_texture == 0)// did not find a matching TGA...
Sys_Error ("Could not load charset, make sure you have every folder and file installed properly\nDouble check that all of your files are in their correct places\nAnd that you have installed the game properly.\n");
start = Hunk_LowMark();
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// free loaded console
Hunk_FreeToLowMark(start);
// save a texture slot for translated picture
translate_texture = texture_extension_number++;
// save slots for scraps
scrap_texnum = texture_extension_number;
texture_extension_number += MAX_SCRAPS;
//
// get the other pics we need
//
sniper_scope = Draw_CachePic ("gfx/hud/scope");
Clear_LoadingFill ();
InitKerningMap();
}
/*
================
Draw_Character
Draws one 8*8 graphics character with 0 being transparent.
It can be clipped to the top of the screen to allow the console to be
smoothly scrolled off.
================
*/
void Draw_Character (int x, int y, int num)
{
int row, col;
float frow, fcol, size;
if (num == 32)
return; // space
num &= 255;
if (y <= -8)
return; // totally off screen
row = num>>4;
col = num&15;
frow = row*0.0625;
fcol = col*0.0625;
size = 0.0625;
GL_Bind (char_texture);
glEnable(GL_ALPHA_TEST);
glBegin (GL_QUADS);
glTexCoord2f (fcol, frow);
glVertex2f (x, y);
glTexCoord2f (fcol + size, frow);
glVertex2f (x+8, y);
glTexCoord2f (fcol + size, frow + size);
glVertex2f (x+8, y+8);
glTexCoord2f (fcol, frow + size);
glVertex2f (x, y+8);
glEnd ();
glDisable(GL_ALPHA_TEST);
}
/*
================
Draw_CharacterRGBA
This is the same as Draw_Character, but with RGBA color codes.
- Cypress
================
*/
extern cvar_t scr_coloredtext;
void Draw_CharacterRGBA(int x, int y, int num, float r, float g, float b, float a, float scale)
{
int row, col;
float frow, fcol, size;
if (num == 32)
return; // space
num &= 255;
if (y <= -8)
return; // totally off screen
row = num>>4;
col = num&15;
frow = row*0.0625f;
fcol = col*0.0625f;
size = 0.0625f*scale;
GL_Bind (char_texture);
glEnable(GL_BLEND);
glColor4f(r/255, g/255, b/255, a/255);
glDisable (GL_ALPHA_TEST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin (GL_QUADS);
glTexCoord2f (fcol, frow);
glVertex2f (x, y);
glTexCoord2f (fcol + (float)(size/(float)scale), frow);
glVertex2f (x+(8*(scale)), y);
glTexCoord2f (fcol + (float)(size/(float)scale), frow + (float)(size/(float)scale));
glVertex2f (x+(8*(scale)), y+(8*(scale)));
glTexCoord2f (fcol, frow + (float)(size/(float)scale));
glVertex2f (x, y+(8*(scale)));
glEnd ();
glColor4f(1,1,1,1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable(GL_ALPHA_TEST);
glDisable (GL_BLEND);
}
/*
================
Draw_String
================
*/
void Draw_String (int x, int y, char *str)
{
Draw_ColoredString(x, y, str, 255, 255, 255, 255, 1);
}
void Draw_ColoredString(int x, int y, char *str, float r, float g, float b, float a, float scale)
{
while (*str)
{
Draw_CharacterRGBA (x, y, *str, r, g, b, a, (int)scale);
// Hooray for variable-spacing!
if (*str == ' ')
x += 4 * (int)scale;
else if ((int)*str < 33 || (int)*str > 126)
x += 8 * (int)scale;
else
x += (font_kerningamount[(int)(*str - 33)] + 1) * (int)scale;
str++;
}
}
int getTextWidth(char *str, float scale)
{
int width = 0;
for (int i = 0; i < strlen(str); i++) {
// Hooray for variable-spacing!
if (str[i] == ' ')
width += 4 * (int)scale;
else if ((int)str[i] < 33 || (int)str[i] > 126)
width += 8 * (int)scale;
else
width += (font_kerningamount[(int)(str[i] - 33)] + 1) * (int)scale;
}
return width;
}
void Draw_ColoredStringCentered(int y, char *str, float r, float g, float b, float a, float scale)
{
Draw_ColoredString((vid.width - getTextWidth(str, scale))/2, y, str, r, g, b, a, scale);
}
/*
================
Draw_DebugChar
Draws a single character directly to the upper right corner of the screen.
This is for debugging lockups by drawing different chars in different parts
of the code.
================
*/
void Draw_DebugChar (char num)
{
}
/*
=============
Draw_AlphaPic
=============
*/
void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha)
{
Draw_ColorPic(x, y, pic, 255, 255, 255, alpha);
}
/*
=============
Draw_Pic
=============
*/
void Draw_Pic (int x, int y, qpic_t *pic)
{
Draw_ColorPic(x, y, pic, 255, 255, 255, 255);
}
/*
=============
Draw_ColoredStretchPic
=============
*/
void Draw_ColoredStretchPic (int x, int y, qpic_t *pic, int x_value, int y_value, int r, int g, int b, int a)
{
glpic_t *gl;
if (scrap_dirty)
Scrap_Upload ();
gl = (glpic_t *)pic->data;
glEnable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glColor4f(r/255.0,g/255.0,b/255.0,a/255.0);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
GL_Bind (gl->texnum);
glBegin (GL_QUADS);
glTexCoord2f (0, 0);
glVertex2f (x, y);
glTexCoord2f (1, 0);
glVertex2f (x+x_value, y);
glTexCoord2f (1, 1);
glVertex2f (x+x_value, y+y_value);
glTexCoord2f (0, 1);
glVertex2f (x, y+y_value);
glEnd ();
glColor4f(1,1,1,1);
}
/*
=============
Draw_StretchPic
=============
*/
void Draw_StretchPic (int x, int y, qpic_t *pic, int x_value, int y_value)
{
glpic_t *gl;
if (scrap_dirty)
Scrap_Upload ();
gl = (glpic_t *)pic->data;
glEnable(GL_ALPHA_TEST);
glColor4f(1,1,1,1);
GL_Bind (gl->texnum);
glBegin (GL_QUADS);
glTexCoord2f (0, 0);
glVertex2f (x, y);
glTexCoord2f (1, 0);
glVertex2f (x+x_value, y);
glTexCoord2f (1, 1);
glVertex2f (x+x_value, y+y_value);
glTexCoord2f (0, 1);
glVertex2f (x, y+y_value);
glEnd ();
glColor4f(1,1,1,1);
}
/*
=============
Draw_ColorPic
=============
*/
void Draw_ColorPic (int x, int y, qpic_t *pic, float r, float g , float b, float a)
{
glpic_t *gl;
if (scrap_dirty)
Scrap_Upload ();
gl = (glpic_t *)pic->data;
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glColor4f(r/255.0f,g/255.0f,b/255.0f,a/255.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
GL_Bind (gl->texnum);
glBegin (GL_QUADS);
glTexCoord2f (0, 0);
glVertex2f (x, y);
glTexCoord2f (1, 0);
glVertex2f (x+pic->width, y);
glTexCoord2f (1, 1);
glVertex2f (x+pic->width, y+pic->height);
glTexCoord2f (0, 1);
glVertex2f (x, y+pic->height);
glEnd ();
glDisable(GL_BLEND);
//glDisable(GL_ALPHA_TEST);
glColor4f(1,1,1,1);
}
/*
=============
Draw_TransPic
=============
*/
void Draw_TransPic (int x, int y, qpic_t *pic)
{
if (x < 0 || (unsigned)(x + pic->width) > vid.width || y < 0 ||
(unsigned)(y + pic->height) > vid.height)
{
Sys_Error ("bad coordinates");
}
Draw_Pic (x, y, pic);
}
/*
=============
Draw_TransPicTranslate
Only used for the player color selection menu
=============
*/
void Draw_TransPicTranslate (int x, int y, qpic_t *pic, byte *translation)
{
int v, u;
unsigned trans[64*64], *dest;
byte *src;
int p;
GL_Bind (translate_texture);
dest = trans;
for (v=0 ; v<64 ; v++, dest += 64)
{
src = &menuplyr_pixels[ ((v*pic->height)>>6) *pic->width];
for (u=0 ; u<64 ; u++)
{
p = src[(u*pic->width)>>6];
if (p == 255)
dest[u] = p;
else
dest[u] = d_8to24table[translation[p]];
}
}
glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor3f (1,1,1);
glBegin (GL_QUADS);
glTexCoord2f (0, 0);
glVertex2f (x, y);
glTexCoord2f (1, 0);
glVertex2f (x+pic->width, y);
glTexCoord2f (1, 1);
glVertex2f (x+pic->width, y+pic->height);
glTexCoord2f (0, 1);
glVertex2f (x, y+pic->height);
glEnd ();
}
/*
================
Draw_ConsoleBackground
================
*/
void Draw_ConsoleBackground (int lines)
{
Draw_FillByColor(0, 0, vid.width, lines, 0, 0, 0, 255);
}
/*
=============
Draw_TileClear
This repeats a 64*64 tile graphic to fill the screen around a sized down
refresh window.
=============
*/
void Draw_TileClear (int x, int y, int w, int h)
{
glColor3f (1,1,1);
GL_Bind (*(int *)draw_backtile->data);
glBegin (GL_QUADS);
glTexCoord2f (x/64.0, y/64.0);
glVertex2f (x, y);
glTexCoord2f ( (x+w)/64.0, y/64.0);
glVertex2f (x+w, y);
glTexCoord2f ( (x+w)/64.0, (y+h)/64.0);
glVertex2f (x+w, y+h);
glTexCoord2f ( x/64.0, (y+h)/64.0 );
glVertex2f (x, y+h);
glEnd ();
}
/*
================
Draw_LoadingFill
By Crow_bar
================
*/
void Draw_LoadingFill(void)
{
if(!loading_num_step)
return;
int size = 8;
int max_step = 350;
int x = (vid.width / 2) - (max_step / 2);
int y = vid.height - (size/ 2) - 25;
char* text;
if(loading_cur_step > loading_num_step)
loading_cur_step = loading_num_step;
if (loading_cur_step < loading_cur_step_bk)
loading_cur_step = loading_cur_step_bk;
if (loading_cur_step == loading_num_step && loading_cur_step_bk != loading_num_step)
loading_cur_step = loading_cur_step_bk;
float loadsize = loading_cur_step * (max_step / loading_num_step);
Draw_FillByColor (x - 2, y - 2, max_step + 4, size + 4, 69, 69, 69, 255);
Draw_FillByColor (x, y, (int)loadsize, size, 0, 0, 0, 200);
switch(loading_step) {
case 1: text = "Loading Models.."; break;
case 2: text = "Loading World.."; break;
case 3: text = "Running Test Frame.."; break;
case 4: text = "Loading Sounds.."; break;
default: text = "Initializing.."; break;
}
Draw_ColoredStringCentered(y, text, 255, 255, 255, 255, 1);
loading_cur_step_bk = loading_cur_step;
}
void Clear_LoadingFill (void)
{
//it is end loading
loading_cur_step = 0;
loading_cur_step_bk = 0;
loading_num_step = 0;
loading_step = -1;
memset(loading_name, 0, sizeof(loading_name));
}
/*
=============
Draw_FillByColor
Fills a box of pixels with a single color
=============
*/
void Draw_FillByColor (int x, int y, int w, int h, int r, int g, int b, int a)
{
glDisable (GL_TEXTURE_2D);
glEnable (GL_BLEND); //johnfitz -- for alpha
glDisable (GL_ALPHA_TEST); //johnfitz -- for alpha
glColor4f ((float)(r/255.0f), (float)(g/255.0f), (float)(b/255.0f), (float)(a/255.0f));
glBegin (GL_QUADS);
glVertex2f (x,y);
glVertex2f (x+w, y);
glVertex2f (x+w, y+h);
glVertex2f (x, y+h);
glEnd ();
glColor4f (1,1,1,1);
glDisable (GL_BLEND); //johnfitz -- for alpha
glEnable(GL_ALPHA_TEST); //johnfitz -- for alpha
glEnable (GL_TEXTURE_2D);
}
//=============================================================================
/*
=============
Batch_FillByColor
Fills a box of pixels with a single color (batched variant)
=============
*/
static qboolean is_batching_fill = qfalse;
void Batch_FillByColor (int x, int y, int w, int h, int r, int g, int b, int a)
{
if (!is_batching_fill) {
is_batching_fill = qtrue;
glDisable (GL_TEXTURE_2D);
glEnable (GL_BLEND); //johnfitz -- for alpha
glDisable (GL_ALPHA_TEST); //johnfitz -- for alpha
glColor4f ((float)(r/255.0f), (float)(g/255.0f), (float)(b/255.0f), (float)(a/255.0f));
glBegin (GL_QUADS);
}
glVertex2f (x,y);
glVertex2f (x+w, y);
glVertex2f (x+w, y+h);
glVertex2f (x, y+h);
}
void Draw_BatchedFill() {
if (is_batching_fill) {
glEnd ();
glColor4f (1,1,1,1);
glDisable (GL_BLEND); //johnfitz -- for alpha
glEnable(GL_ALPHA_TEST); //johnfitz -- for alpha
glEnable (GL_TEXTURE_2D);
is_batching_fill = qfalse;
}
}
byte *StringToRGB (char *s)
{
byte *col;
static byte rgb[4];
Cmd_TokenizeString (s);
if (Cmd_Argc() == 3)
{
rgb[0] = (byte)Q_atoi(Cmd_Argv(0));
rgb[1] = (byte)Q_atoi(Cmd_Argv(1));
rgb[2] = (byte)Q_atoi(Cmd_Argv(2));
}
else
{
col = (byte *)&d_8to24table[(byte)Q_atoi(s)];
rgb[0] = col[0];
rgb[1] = col[1];
rgb[2] = col[2];
}
rgb[3] = 255;
return rgb;
}
extern cvar_t crosshair;
extern qboolean croshhairmoving;
//extern cvar_t cl_zoom;
extern qpic_t *hitmark;
double Hitmark_Time, crosshair_spread_time;
float cur_spread;
float crosshair_offset_step;
int CrossHairWeapon (void)
{
int i;
switch(cl.stats[STAT_ACTIVEWEAPON])
{
case W_COLT:
case W_BIATCH:
case W_357:
case W_KILLU:
i = 22;
break;
case W_PTRS:
case W_PENETRATOR:
case W_KAR_SCOPE:
case W_HEADCRACKER:
case W_KAR:
case W_ARMAGEDDON:
case W_SPRING:
case W_PULVERIZER:
i = 65;
break;
case W_MP40:
case W_AFTERBURNER:
case W_STG:
case W_SPATZ:
case W_THOMPSON:
case W_GIBS:
case W_BAR:
case W_WIDOW:
case W_PPSH:
case W_REAPER:
case W_RAY:
case W_PORTER:
case W_TYPE:
case W_SAMURAI:
case W_FG:
case W_IMPELLER:
case W_MP5:
case W_KOLLIDER:
i = 10;
break;
case W_BROWNING:
case W_ACCELERATOR:
case W_MG:
case W_BARRACUDA:
i = 30;
break;
case W_SAWNOFF: