Skip to content

Commit 1950b42

Browse files
committed
TTF font support
Text is now rendered with ttf files instead of bitmap fonts. Adds a dependency on `SDL2_ttf`. Console text is rendered character by character, and will support a limited set of Unicode characters. UI text is rendered by passing the whole string to `SDL2_ttf` and supports all of Unicode. Multiple ttf files can be specified for each font, one for each writing script. The writing script to use can be specified with `uifont`. The `textbright` and `uitextrows` variables, and the `tabify` command have been removed. the valid range for `conscale` has been restricted to [0.5, 2] and the default value has been changed to 1. Added configuration variables: - conshadow(0, 255, 255): controls the intensity of the shadow added to console text to increase visibility - uifps(0, 60, 1000): controls the maximum rate at which UI text element update their contents; set to zero to disable the limit
1 parent 1018b4a commit 1950b42

27 files changed

Lines changed: 861 additions & 550 deletions

config/font.cfg

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11

22
// Execute dedicated game fonts here
33

4-
loopfiles f "data/interface/font" cfg [
5-
exec (+s "data/interface/font/" $f ".cfg")
6-
]
4+
// font name filename.ttf
5+
// fontface script rtl? filename.ttf
76

8-
// Change the two following lines to define default font
9-
fontalias "default" "main"
10-
fontalias "default.ol" "main.ol"
7+
// valid script names are defined in /usr/include/harfbuzz/hb-common.h
118

12-
// Shorthand aliases
13-
fontalias "def" "default"
14-
fontalias "def.ol" "default.ol"
9+
font "default" "data/interface/font/Roboto-Regular.ttf"
10+
font "mono" "data/interface/font/DejaVuSansMono.ttf"
11+
font "wide" "data/interface/font/vipnagor.ttf"
12+
font "webdings" "data/interface/font/webdings.ttf"

config/glsl/hud.cfg

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,6 @@ shader 0 "hud" [
2828
}
2929
]
3030

31-
shader 0 "hudtext" [
32-
attribute vec4 vvertex, vcolor;
33-
attribute vec2 vtexcoord0;
34-
uniform mat4 hudmatrix;
35-
varying vec2 texcoord0;
36-
varying vec4 colorscale;
37-
void main(void)
38-
{
39-
gl_Position = hudmatrix * vvertex;
40-
texcoord0 = vtexcoord0;
41-
colorscale = vcolor;
42-
}
43-
] [
44-
uniform sampler2D tex0;
45-
uniform vec4 textparams;
46-
varying vec2 texcoord0;
47-
varying vec4 colorscale;
48-
fragdata(0) vec4 fragcolor;
49-
void main(void)
50-
{
51-
float dist = texture2D(tex0, texcoord0).r;
52-
float border = smoothstep(textparams.x, textparams.y, dist);
53-
float outline = smoothstep(textparams.z, textparams.w, dist);
54-
fragcolor = vec4(colorscale.rgb * outline, colorscale.a * border);
55-
}
56-
]
57-
5831
shader 0 "hudrgb" [
5932
attribute vec4 vvertex, vcolor;
6033
attribute vec2 vtexcoord0;

config/glsl/particle.cfg

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,13 @@ shader 0 "particletext" [
107107
color = vec4(vcolor.rgb * ldrscale, vcolor.a);
108108
}
109109
] [
110-
uniform vec4 textparams;
111-
uniform sampler2D tex0;
110+
uniform sampler2DRect tex0;
112111
varying vec4 color;
113112
varying vec2 texcoord0;
114113
fragdata(0) vec4 fragcolor;
115114
void main(void)
116115
{
117-
float dist = texture2D(tex0, texcoord0).r;
118-
float border = smoothstep(textparams.x, textparams.y, dist);
119-
float outline = smoothstep(textparams.z, textparams.w, dist);
120-
fragcolor = vec4(color.rgb * outline, color.a * border);
116+
fragcolor = color * texture2DRect(tex0, texcoord0);
121117
}
122118
]
123119

config/ui/hud/editstats.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ uiLiteMenu "edithud" [
333333
uigrid 2 $uiPad:3XL $uiPad:L [
334334
uihlist $uiPad:XL [
335335
uitext "WTR" 0.5
336-
uitext (tabify (format "%1k" $editstatwtr) 1) 0.5
337-
uitext (tabify (format "(%1%%)" $editstatvtr) 2) 0.5
336+
uitext (format "%1k" $editstatwtr) 0.5
337+
uitext (format "(%1%%)" $editstatvtr) 0.5
338338
]
339339
uihlist $uiPad:XL [
340340
uitext "WVT" 0.5

config/ui/hud/gamehud.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ newui "scoreboard" [
735735
uiFastImg (fade (? $arg1 0.5 0.25)) "hud/" "shelf" "" $uiPad:5XL
736736
uiFastImg <mad:.18/.18/.18> "hud/" "glow" "" $uiPad:5XL
737737
push n (+ $n 1) [
738-
uifontcolortext "def.ol" $n (|A! (? $arg1 0xB0 0x60)) 0.55
738+
uifontcolortext "default" $n (|A! (? $arg1 0xB0 0x60)) 0.55
739739
]
740740
] ; uialign- -1
741741
]
@@ -786,14 +786,14 @@ newui ".killUI" [
786786
uifill 0 0.3
787787
t = (getrespawnwait)
788788
uispace 0.02 0.02 [
789-
uifonttext "wide.ol" $lasthudkillinfo $uiPad:USS
789+
uifonttext "wide" $lasthudkillinfo $uiPad:USS
790790
]
791791
uispace 0 0 [
792792
uioffset 0 $uiPad:D2XL- [
793793
if (m_invasion $getmode) [
794-
uifonttext "wide.ol" (+s "^f4Lives remaining: " $getclientlives) $uiPad:USS
794+
uifonttext "wide" (+s "^f4Lives remaining: " $getclientlives) $uiPad:USS
795795
] [
796-
uifontcolortext "wide.ol" (? $t $t " ") (? (< (getmillis) (+ 100 (getlastspawnattempt))) $c_red $c_white) 1
796+
uifontcolortext "wide" (? $t $t " ") (? (< (getmillis) (+ 100 (getlastspawnattempt))) $c_red $c_white) 1
797797
]
798798
]
799799
]

config/ui/hud/geo_prefab.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ uiLiteMenu "geo_prefab" [
2424
uiclamp*e
2525
uispace $uiPad:S $uiPad:O3 [
2626
uialign -1 -1
27-
uifontcolortext "def.ol" $i (|A! 0x98) 0.55
27+
uifontcolortext "default" $i (|A! 0x98) 0.55
2828
]
2929
uihover [
3030
if (!= $i $.UI_obrsel) [

config/ui/hud/mapmodel_browser.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ uiLiteMenu "mapmodel_browser" [
5454
uimodelpreview (mapmodelname $i 1) "mapmodel"
5555
uiclamp*e
5656
uispace $uiPad:S $uiPad:O3 [
57-
uifonttext "def.ol" $i 0.55
57+
uifonttext "default" $i 0.55
5858
] ; uialign- -1 -1
5959
if (iskeyheld "LSHIFT") [
6060
uispace $uiPad:S 0 [
61-
uifonttext "webdings.ol" "q" 0.65
61+
uifonttext "webdings" "q" 0.65
6262
] ; uialign- -1 1
6363
uirelease [ clearmodel (+s "mapmodel/" (mapmodelname $i)) ]
6464
] [
@@ -77,14 +77,14 @@ uiLiteMenu "mapmodel_browser" [
7777
uimodelpreview (mapmodelname $i 1) "mapmodel"
7878
uiclamp*e
7979
uispace $uiPad:S $uiPad:O3 [
80-
uifontcolortext "def.ol" $i (|A! 0xA0) 0.55
80+
uifontcolortext "default" $i (|A! 0xA0) 0.55
8181
] ; uialign- -1 -1
8282
uihover [ .mm_selidx = $n ; uiSetMillis ]
8383
uioutline $c_line1 $.z $.z
8484
]
8585
if (mapmodelloaded $i) [
8686
uispace $uiPad:S $uiPad:O3 [
87-
uifonttext "webdings.ol" "a" 0.55
87+
uifonttext "webdings" "a" 0.55
8888
] ; uialign- 1 -1
8989
]
9090
uiHoverOnce [ uiHoverSound ]

config/ui/hud/texture_browser.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ uiLiteMenu "texture_browser" [
2929
]
3030
uispace $uiPad:S $uiPad:O3 [
3131
uialign -1 -1
32-
uifontcolortext "def.ol" $i (|A! 0x98) 0.55
32+
uifontcolortext "default" $i (|A! 0x98) 0.55
3333
]
3434
]
3535
uipress [ uiSetMillis ]
@@ -83,7 +83,7 @@ uiLiteMenu "texture_browser" [
8383
uiclip 0 $uiPad:6XL [ uicolortext "/" $c_gray 1.2 ]
8484
] // text takes up a lot of vertical space, have to "cut" it
8585
uifill $uiPad:DXS 0 [
86-
uifonttext "def.ol" (max $.tb_totalpg 1) 0.7
86+
uifonttext "default" (max $.tb_totalpg 1) 0.7
8787
uialign- -1 1
8888
]
8989
uiclamp*y
@@ -110,7 +110,7 @@ uiLiteMenu "texture_browser" [
110110
uislotview $i
111111
uiclamp*e
112112
uispace $uiPad:S $uiPad:O3 [
113-
uifontcolortext "def.ol" $i (|A! 0xA0) 0.55
113+
uifontcolortext "default" $i (|A! 0xA0) 0.55
114114
] ; uialign- -1 -1
115115
uirelease [
116116
settex (getslottex $i)

config/ui/lib.cfg

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -793,12 +793,12 @@ uiButton = [
793793

794794
// uiFancyText FONT TEXT SIZE 0xCOLOR TRANSPARENCY
795795
uiFancyText = [
796-
if (=s $arg1 "") [ arg1 = "def" ]
796+
if (=s $arg1 "") [ arg1 = "default" ]
797797
if $arg4 [] [ arg4 = $c_white ]
798798
if (< $numargs 5) [ arg5 = 1 ]
799799
uigroup [
800800
uioffset $uiPad:O1- $uiPad:O1 [
801-
uifontcolortext [@arg1.ol] (stripcolors $arg2) (|A (*fA $arg5 0x20)) $arg3
801+
uifontcolortext $arg1 (stripcolors $arg2) (|A (*fA $arg5 0x20)) $arg3
802802
uifontcolortext $arg1 (stripcolors $arg2) (|A (*fA $arg5)) $arg3
803803
]
804804
uioffset $uiPad:O1 $uiPad:O1- [
@@ -809,7 +809,7 @@ uiFancyText = [
809809

810810
// uiEmbossText FONT TEXT SIZE 0xCOLOR
811811
uiEmbossText = [
812-
if (=s $arg1 "") [ arg1 = "def" ]
812+
if (=s $arg1 "") [ arg1 = "default" ]
813813
uigroup [
814814
uioffset $uiPad:O2- $uiPad:O2 [
815815
uifontcolortext $arg1 (stripcolors $arg2) 0 $arg3
@@ -851,7 +851,7 @@ uiVerSld = [
851851
] ; uiclamp-x
852852
uivlist $uiPad:M- [
853853
loop i (strlen $arg6) [
854-
uifontcolortext "def.ol" (substr $arg6 $i 1) (|A! (? $arg9 0xA0 0x60)) 0.65
854+
uifontcolortext "default" (substr $arg6 $i 1) (|A! (? $arg9 0xA0 0x60)) 0.65
855855
]
856856
]
857857
]
@@ -880,7 +880,7 @@ uiHorSld = [
880880
uiclamp*y
881881
]
882882
] ; uiclamp-y
883-
uifontcolortext "def.ol" $arg6 (|A! (? $arg9 0xA0 0x60)) 0.65
883+
uifontcolortext "default" $arg6 (|A! (? $arg9 0xA0 0x60)) 0.65
884884
]
885885
uiclamp*e
886886
]
@@ -910,7 +910,7 @@ uiVerColorSld = [
910910
] ; uiclamp-x
911911
uivlist $uiPad:M- [
912912
loop i (strlen $$arg1) [
913-
uifontcolortext "wide.ol" (substr $$arg1 $i 1) (|A! (? $arg9 0xA0 0x60)) 0.7
913+
uifontcolortext "wide" (substr $$arg1 $i 1) (|A! (? $arg9 0xA0 0x60)) 0.7
914914
]
915915
]
916916
]
@@ -940,7 +940,7 @@ uiHorColorSld = [
940940
uiclamp*y
941941
]
942942
] ; uiclamp-y
943-
uifontcolortext "wide.ol" $$arg1 (|A! (? $arg9 0xA0 0x60)) 0.7
943+
uifontcolortext "wide" $$arg1 (|A! (? $arg9 0xA0 0x60)) 0.7
944944
]
945945
uiclamp*e
946946
]

config/ui/libnew.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ uiSliderH = [
170170
uiFastImgStretched "" "shadow2" "" "" [ uiclamp.x ]
171171
uiclamp*e
172172
if $arg9 [ arg10 = 0xA0FFFFFF ] [ arg10 = 0x60FFFFFF ]
173-
uiFontColorText "def.ol" $arg6 0.65 $arg10
173+
uiFontColorText "default" $arg6 0.65 $arg10
174174
] ; uiclamp-y
175175
]
176176
] ; uiclamp-y

0 commit comments

Comments
 (0)