-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfonts.cpp
More file actions
executable file
·1903 lines (1813 loc) · 49.7 KB
/
fonts.cpp
File metadata and controls
executable file
·1903 lines (1813 loc) · 49.7 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
//Fonts for use with OpenGL
//Gordon Griesel
//2007 - 2017
//
//Texture-mapped fonts.
//Look at the code and .ppm files to see how you might add fonts of your own.
//
#include "defs.h"
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#ifdef __APPLE__
#else
#include <malloc.h>
#endif
#include <stdarg.h>
#include <unistd.h>
#include <GL/glx.h>
//#include "ppm.h"
#include "log.h"
//To save compressed files to fonttex.cpp...
//1. deactivate read-from-compressed
// activate show-compressed-printout
//2. compile and run ggtest
//3. rename x.x to fonttex.cpp
//4. activate read-from-compressed
// deactivate show-compressed-printout
//#define SHOW_COMPRESSED_PRINTOUT
#define READ_FROM_COMPRESSED
#define RGB(r,g,b) ((int)r + (int)((int)g<<8) + (int)((int)b<<16))
#define GetRValue(rgb) (unsigned char)((unsigned int)rgb&0x000000ff)
#define GetGValue(rgb) (unsigned char)((unsigned int) \
((unsigned int)rgb&0x0000ff00) >> 8)
#define GetBValue(rgb) (unsigned char)((unsigned int) \
((unsigned int)rgb&0x00ff0000) >> 16)
int cstart_a06[128], clen_a06[128];
int cstart_a07[128], clen_a07[128];
int cstart_a08[128], clen_a08[128];
int cstart_a8b[128], clen_a8b[128];
int cstart_a12[128], clen_a12[128];
int cstart_a13[128], clen_a13[128];
int cstart_a10[128], clen_a10[128];
int cstart_a16[128], clen_a16[128];
int cstart_c17[128], clen_c17[128];
int cstart_a40[128], clen_a40[128];
float tx_a06[128][2], ty_a06[128][2];
float tx_a07[128][2], ty_a07[128][2];
float tx_a08[128][2], ty_a08[128][2];
float tx_a8b[128][2], ty_a8b[128][2];
float tx_a10[128][2], ty_a10[128][2];
float tx_a12[128][2], ty_a12[128][2];
float tx_a13[128][2], ty_a13[128][2];
float tx_a16[128][2], ty_a16[128][2];
float tx_c17[128][2], ty_c17[128][2];
float tx_a40[128][2], ty_a40[128][2];
//
unsigned int a06_texture_no;
unsigned int a07_texture_no;
unsigned int a08_texture_no;
unsigned int a8b_texture_no;
unsigned int a10_texture_no;
unsigned int a12_texture_no;
unsigned int a13_texture_no;
unsigned int a16_texture_no;
unsigned int c17_texture_no;
unsigned int a40_texture_no;
//
void initialize_fonts(void);
void cleanup_fonts(void);
void get_compressed_tm(Texmap *tm, unsigned char *ptr1);
void build_gl_texmap(Texmap *tm, unsigned int *texnum);
void load_ggfont(int psize);
void ggprint06(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint07(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint08(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint8b(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint10(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint12(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint13(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint16(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint17(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint40(Rect *r, int advance, int cref, const char *fmt, ...);
//void ggprint8b_sz(Rect *r, int adv, int cref, int sz, const char *fmt, ...);
void ggprint16_sz(Rect *r, int adve, int cref, float sz, const char *fmt, ...);
int ggprint8b_chat(Rect *r, int advance, int cref, const char *fmt, ...);
int ggprint8b_wordwrap(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint13nb(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint06nb(Rect *r, int advance, int cref, const char *fmt, ...);
void ggprint8b_nb(Rect *r, int advance, int cref, const char *fmt, ...);
int get_length(const char *fmt, ...);
int find_next_white(Texmap *tm, int *xpos);
int find_next_yellow(Texmap *tm, int *xpos);
int tex_read_ggfont_bmp(char *fileName, Texmap *tm);
int read_texture_from_ppm(const char *fileName);
//#define STOP_ALL_FONT_WRITING
// !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_'abcdefghijklmnopqrstuvwxyz{|}~
//
extern unsigned char ams6ppm[];
extern unsigned char av7ppm[];
extern unsigned char arial8ppm[];
extern unsigned char arial8bppm[];
extern unsigned char arial10ppm[];
extern unsigned char arial12ppm[];
extern unsigned char arial13ppm[];
extern unsigned char arial16ppm[];
extern unsigned char courier16ppm[];
extern unsigned char arial40ppm[];
unsigned char *tempbmp;
unsigned char *tempptr;
//the ppm functions brought in from ppm utilities.
typedef struct t_ppmimage {
int width;
int height;
void *data;
} Ppmimage;
Ppmimage *ppm6GetImage_local(const char *filename)
{
int i, j, width, height, size, maxval, ntries;
char ts[4096];
unsigned char c;
unsigned char *p;
FILE *fpi;
Ppmimage *image = (Ppmimage *)malloc(sizeof(Ppmimage));
if (!image) {
printf("ERROR: out of memory\n");
exit(EXIT_FAILURE);
}
fpi = fopen(filename, "r");
if (!fpi) {
printf("ERROR: cannot open file **%s** for reading.\n", filename);
exit(EXIT_FAILURE);
}
image->data=NULL;
char *x = fgets(ts, 4, fpi);
if (x){}
if (strncmp(ts, "P6" ,2) != 0) {
printf("ERROR: File is not ppm RAW format.\n");
exit(EXIT_FAILURE);
}
//comments?
while(1) {
c = fgetc(fpi);
if (c != '#')
break;
//read until newline
ntries=0;
while(1) {
//to avoid infinite loop...
if (++ntries > 10000) {
printf("ERROR: too many blank lines in **%s**\n", filename);
exit(EXIT_FAILURE);
}
c = fgetc(fpi);
if (c == '\n')
break;
}
}
ungetc(c, fpi);
int r = fscanf(fpi, "%u%u%u", &width, &height, &maxval);
if (r){}
//
//get past any newline or carrage-return
ntries=0;
while(1) {
//to avoid infinite loop...
if (++ntries > 10000) {
printf("ERROR: too many blank lines in **%s**\n", filename);
exit(EXIT_FAILURE);
}
c = fgetc(fpi);
if (c != 10 && c != 13) {
ungetc(c, fpi);
break;
}
}
//
size = width * height * 3;
image->data = (unsigned char *)malloc(size);
if (!image->data) {
printf("ERROR: no memory for image data.\n");
exit(EXIT_FAILURE);
}
image->width = width;
image->height = height;
p = (unsigned char *)image->data;
for (i=0; i<height; i++) {
for (j=0; j<width; j++) {
*p = fgetc(fpi); p++;
*p = fgetc(fpi); p++;
*p = fgetc(fpi); p++;
}
}
fclose(fpi);
return image;
}
void ppm6CleanupImage_local(Ppmimage *image)
{
if (image != NULL) {
if (image->data != NULL)
free(image->data);
free(image);
}
}
int texState()
{
#ifdef READ_FROM_COMPRESSED
return 0;
#else //READ_FROM_COMPRESSED
return 1;
#endif //READ_FROM_COMPRESSED
}
int get_length(const char *fmt, ...)
{
int k;
char text[512];
va_list ap;
if (fmt == NULL)
return 0;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
const int slen = strlen(text);
int fx = 0;
for (k=0; k<slen; ++k) {
fx += ((clen_a8b[(text[k]-32)])) + 1;
}
return fx;
}
void ggprint16_sz(Rect *r, int advance, int cref, float sz, const char *fmt, ...)
{
int k, ascii;
float tx[2],ty[2];
float fx = (float)(r->left);
float fy = (float)(r->bot);
float lp;
//height of the @ symbol is 46 (span of the largest symbol)
const float hp = 46.0f;
//height of the @ symbol is 46 (span of the largest symbol)
//const float hp = 20.0f;
//printf("ggprint16_sz()...\n");
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
glBindTexture(GL_TEXTURE_2D, a16_texture_no);
const int slen = strlen(text);
if (r->center) {
for (k=0; k<slen; ++k) {
fx += ((float)(clen_a16[(text[k]-32)]*sz)) + 4.0f*sz;
}
//backup text start position.
const int tlen = (int)fx - r->left;
fx = (float)(r->left - (tlen>>1));
}
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a16[ascii]);
tx[0] = tx_a16[ascii][0];
tx[1] = tx_a16[ascii][1];
ty[0] = ty_a16[ascii][0];
ty[1] = ty_a16[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp*sz);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp*sz,fy+hp*sz);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp*sz,fy);
fx += (lp*sz + 4.0f*sz);
}
glEnd();
//printf("tlen:%f\n",tlen);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_ALPHA_TEST);
r->bot -= (int)( (float)advance * sz );
}
void ggprint8b(Rect *r, int advance, int cref, const char *fmt, ...)
{
int k, ascii;
float tx[2],ty[2];
float fx = (float)(r->left);
float fy = (float)(r->bot);
float lp;
const float hp = 10.0f; //max height of tallest symbol
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
glBindTexture(GL_TEXTURE_2D, a8b_texture_no);
const int slen = strlen(text);
if (r->center) {
for (k=0; k<slen; ++k) {
fx += ((float)(clen_a8b[(text[k]-32)])) + 1.0f;
}
//backup text start position.
const int tlen = (int)fx - r->left;
fx = (float)(r->left - (tlen>>1));
}
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a8b[ascii]);
tx[0] = tx_a8b[ascii][0];
tx[1] = tx_a8b[ascii][1];
ty[0] = ty_a8b[ascii][0];
ty[1] = ty_a8b[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += (lp + 1.0f);
}
glEnd();
//printf("tlen:%f\n",tlen);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_ALPHA_TEST);
r->bot -= advance;
}
int ggprint8b_wordwrap(Rect *r, int advance, int cref, const char *fmt, ...)
{
//returns 2 if line had to be wrapped.
int k, ascii;
float tx[2],ty[2];
float fx = (float)(r->left);
float fy = (float)(r->bot);
float lp;
const float hp = 10.0f; //max height of tallest symbol
const int rmargin = r->right;
const int lmargin = r->top;
int ret=1;
//printf("ggprint8b_wordwrap(rmargin: %i)...\n",rmargin);
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return 0;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
glBindTexture(GL_TEXTURE_2D, a8b_texture_no);
const int slen = strlen(text);
//Will the text overrun the right margin???
int bspot =0;
int lastspace=0;
float tfx = fx;
for (k=0; k<slen; ++k) {
if (text[k] == 32) lastspace = k;
tfx += ((float)(clen_a8b[(text[k]-32)])) + 1.0f;
if ( (int)tfx > rmargin) { bspot = k; break; }
}
glBegin(GL_QUADS);
if ( bspot ) {
//Text overruns the right margin, at bspot.
//printf("Text overruns the right margin.
//bspot: %i lastspace: %i\n",bspot,lastspace);
if (!lastspace) {
//No spaces were found before the overrun.
//User typed a long continuous string of characters.
//Just print it, and look for any space following it.
//Start next string there.
for (k=0; k<bspot; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a8b[ascii]);
tx[0] = tx_a8b[ascii][0];
tx[1] = tx_a8b[ascii][1];
ty[0] = ty_a8b[ascii][0];
ty[1] = ty_a8b[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += (lp + 1.0f);
}
//look for a space in the string before a null.
int start=0;
for (k=bspot; k<slen; ++k) {
if (text[k] == 32) { start = k; break; }
}
if (start) {
//printf("found a space after the break.\n");
//There is some more string to print out.
fx = (float)lmargin;
r->bot -= advance;
fy = (float)(r->bot);
for (k=bspot; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a8b[ascii]);
tx[0] = tx_a8b[ascii][0];
tx[1] = tx_a8b[ascii][1];
ty[0] = ty_a8b[ascii][0];
ty[1] = ty_a8b[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += (lp + 1.0f);
}
}
}
else {
//A space was found before the overrun.
//Print the line up to that space.
for (k=0; k<lastspace; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a8b[ascii]);
tx[0] = tx_a8b[ascii][0];
tx[1] = tx_a8b[ascii][1];
ty[0] = ty_a8b[ascii][0];
ty[1] = ty_a8b[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += (lp + 1.0f);
}
//There is some more string to print out.
fx = (float)lmargin;
r->bot -= advance;
fy = (float)(r->bot);
for (k=lastspace+1; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a8b[ascii]);
tx[0] = tx_a8b[ascii][0];
tx[1] = tx_a8b[ascii][1];
ty[0] = ty_a8b[ascii][0];
ty[1] = ty_a8b[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += (lp + 1.0f);
}
}
ret=2;
}
else {
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a8b[ascii]);
tx[0] = tx_a8b[ascii][0];
tx[1] = tx_a8b[ascii][1];
ty[0] = ty_a8b[ascii][0];
ty[1] = ty_a8b[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += (lp + 1.0f);
}
}
glEnd();
//printf("tlen:%f\n",tlen);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_ALPHA_TEST);
r->bot -= advance;
return ret;
}
int ggprint8b_chat(Rect *r, int advance, int cref, const char *fmt, ...)
{
//returns the last position, so we can show a blinking cursor.
int k, ascii;
float tx[2],ty[2];
float fx = (float)(r->left);
float fy = (float)(r->bot);
float lp;
const float hp = 10.0f; //max height of tallest symbol
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return 0;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
glBindTexture(GL_TEXTURE_2D, a8b_texture_no);
const int slen = strlen(text);
if (r->center) {
for (k=0; k<slen; ++k) {
//ascii = text[k] - 32;
//fx += ((float)(clen_a8b[ascii])) + 1.0f;
fx += ((float)(clen_a8b[(text[k]-32)])) + 1.0f;
}
//backup text start position.
const int tlen = (int)fx - r->left;
fx = (float)(r->left - (tlen>>1));
}
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a8b[ascii]);
tx[0] = tx_a8b[ascii][0];
tx[1] = tx_a8b[ascii][1];
ty[0] = ty_a8b[ascii][0];
ty[1] = ty_a8b[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += (lp + 1.0f);
}
glEnd();
//printf("tlen:%f\n",tlen);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_ALPHA_TEST);
r->bot -= advance;
return (int)fx - r->left;
}
void ggprint8b_nb(Rect *r, int advance, int cref, const char *fmt, ...)
{
int k, ascii;
float tx[2],ty[2];
float fx = (float)(r->left);
const float fy = (float)(r->bot);
float lp;
const float hp = 10.0f; //max height of tallest symbol
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
const int slen = strlen(text);
if (r->center) {
for (k=0; k<slen; ++k) {
fx += ((float)(clen_a8b[(text[k] - 32)])) + 1.0f;
}
//backup text start position.
const int tlen = (int)fx - r->left;
fx = (float)(r->left - (tlen>>1));
}
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a8b[ascii]);
tx[0] = tx_a8b[ascii][0];
tx[1] = tx_a8b[ascii][1];
ty[0] = ty_a8b[ascii][0];
ty[1] = ty_a8b[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += (lp + 1.0f);
}
glEnd();
r->bot -= advance;
}
void ggprint06(Rect *r, int advance, int cref, const char *fmt, ...)
{
int k, ascii;
float tx[2],ty[2];
float fx = (float)(r->left);
float fy = (float)(r->bot);
float lp;
const float hp = 10.0f; //max height of tallest symbol
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
glBindTexture(GL_TEXTURE_2D, a06_texture_no);
const int slen = strlen(text);
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a06[ascii]);
tx[0] = tx_a06[ascii][0];
tx[1] = tx_a06[ascii][1];
ty[0] = ty_a06[ascii][0];
ty[1] = ty_a06[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += lp + 1.0f;
}
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_ALPHA_TEST);
r->bot -= advance;
}
void ggprint06nb(Rect *r, int advance, int cref, const char *fmt, ...)
{
int k, ascii;
float tx[2],ty[2];
float fx = (float)(r->left);
float fy = (float)(r->bot);
float lp;
const float hp = 10.0f; //max height of tallest symbol
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
const int slen = strlen(text);
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a06[ascii]);
tx[0] = tx_a06[ascii][0];
tx[1] = tx_a06[ascii][1];
ty[0] = ty_a06[ascii][0];
ty[1] = ty_a06[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += lp + 1.0f;
}
glEnd();
r->bot -= advance;
}
void ggprint07(Rect *r, int advance, int cref, const char *fmt, ...)
{
int k, ascii;
float tx[2],ty[2];
float fx = (float)(r->left);
float fy = (float)(r->bot);
float lp;
const float hp = 10.0f; //max height of tallest symbol
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
glBindTexture(GL_TEXTURE_2D, a07_texture_no);
const int slen = strlen(text);
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a07[ascii]);
tx[0] = tx_a07[ascii][0];
tx[1] = tx_a07[ascii][1];
ty[0] = ty_a07[ascii][0];
ty[1] = ty_a07[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += lp + 1.0f;
}
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_ALPHA_TEST);
r->bot -= advance;
}
void ggprint08(Rect *r, int advance, int cref, const char *fmt, ...)
{
int k, ascii;
float tx[2],ty[2];
float fx = (float)(r->left);
float fy = (float)(r->bot);
float lp;
const float hp = 10.0f; //max height of tallest symbol
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
glBindTexture(GL_TEXTURE_2D, a08_texture_no);
const int slen = strlen(text);
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a08[ascii]);
tx[0] = tx_a08[ascii][0];
tx[1] = tx_a08[ascii][1];
ty[0] = ty_a08[ascii][0];
ty[1] = ty_a08[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += lp + 1.0f;
}
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_ALPHA_TEST);
r->bot -= advance;
}
void ggprint10(Rect *r, int advance, int cref, const char *fmt, ...)
{
int k, ascii;
float tx[2],ty[2];
float fx = (float)(r->left);
float fy = (float)(r->bot);
float lp;
const float hp = 13.0f; //max height of tallest symbol
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
glBindTexture(GL_TEXTURE_2D, a10_texture_no);
const int slen = strlen(text);
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a10[ascii]);
tx[0] = tx_a10[ascii][0];
tx[1] = tx_a10[ascii][1];
ty[0] = ty_a10[ascii][0];
ty[1] = ty_a10[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx, fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx, fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += lp + 1.0f;
}
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_ALPHA_TEST);
r->bot -= advance;
}
void ggprint13(Rect *r, int advance, int cref, const char *fmt, ...)
{
//this is a bold 12 point font.
int k, ascii;
float tx[2],ty[2];
float fx = (float)r->left;
float fy = (float)r->bot;
float lp;
const float hp = 16.0f; //max height of tallest symbol
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
glBindTexture(GL_TEXTURE_2D, a13_texture_no);
const int slen = strlen(text);
if (slen > 200) return;
if (r->center) {
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
fx += ((float)(clen_a13[ascii])) + 1.0f;
}
//backup text start position.
const int tlen = (int)fx - r->left;
fx = (float)(r->left - (tlen>>1));
}
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a13[ascii]);
tx[0] = tx_a13[ascii][0];
tx[1] = tx_a13[ascii][1];
ty[0] = ty_a13[ascii][0];
ty[1] = ty_a13[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx,fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx,fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += lp + 1.0f;
}
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_ALPHA_TEST);
r->bot -= advance;
}
void ggprint13nb(Rect *r, int advance, int cref, const char *fmt, ...)
{
//do not bind the texture.
//this is a bold 12 point font.
int k, ascii;
float tx[2],ty[2];
float fx = (float)r->left;
float fy = (float)r->bot;
float lp;
const float hp = 16.0f; //max height of tallest symbol
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
const int slen = strlen(text);
if (slen > 200) return;
if (r->center) {
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
fx += ((float)(clen_a13[ascii])) + 1.0f;
}
//backup text start position.
const int tlen = (int)fx - r->left;
fx = (float)(r->left - (tlen>>1));
}
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a13[ascii]);
tx[0] = tx_a13[ascii][0];
tx[1] = tx_a13[ascii][1];
ty[0] = ty_a13[ascii][0];
ty[1] = ty_a13[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx,fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx,fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += lp + 1.0f;
}
glEnd();
r->bot -= advance;
}
void ggprint12(Rect *r, int advance, int cref, const char *fmt, ...)
{
int k, ascii;
float tx[2],ty[2];
float fx = (float)r->left;
float fy = (float)r->bot;
float lp;
const float hp = 16.0f; //max height of tallest symbol
#ifdef STOP_ALL_FONT_WRITING
return;
#endif //STOP_ALL_FONT_WRITING
char text[512];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
//
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glColor4ub(GetBValue(cref),GetGValue(cref),GetRValue(cref), 255);
glBindTexture(GL_TEXTURE_2D, a12_texture_no);
const int slen = strlen(text);
// glBegin(GL_QUADS);
// for (k=0; k<slen; ++k) {
// ascii = text[k] - 32;
// lp = (float)(clen_a12[ascii]);
// tx[0] = tx_a12[ascii][0]; tx[1] = tx_a12[ascii][1]; ty[0] = ty_a12[ascii][0]; ty[1] = ty_a12[ascii][1];
// glTexCoord2f(tx[0],ty[0]); glVertex2f(fx,fy);glTexCoord2f(tx[0],ty[1]); glVertex2f(fx,fy+hp);glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
// fx += lp + 1.0f;
// }
if (r->center) {
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
fx += ((float)(clen_a12[ascii])) + 1.0f;
}
//backup text start position.
const int tlen = (int)fx - r->left;
fx = (float)(r->left - (tlen>>1));
}
glBegin(GL_QUADS);
for (k=0; k<slen; ++k) {
ascii = text[k] - 32;
lp = (float)(clen_a12[ascii]);
tx[0] = tx_a12[ascii][0];
tx[1] = tx_a12[ascii][1];
ty[0] = ty_a12[ascii][0];
ty[1] = ty_a12[ascii][1];
glTexCoord2f(tx[0],ty[0]); glVertex2f(fx,fy);
glTexCoord2f(tx[0],ty[1]); glVertex2f(fx,fy+hp);
glTexCoord2f(tx[1],ty[1]); glVertex2f(fx+lp,fy+hp);
glTexCoord2f(tx[1],ty[0]); glVertex2f(fx+lp,fy);
fx += lp + 1.0f;