-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmfdemo.bmx
204 lines (158 loc) · 5.53 KB
/
bmfdemo.bmx
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
Strict
Import wiering.bmfont
'AutoImageFlags MASKEDIMAGE | FILTEREDIMAGE
AutoImageFlags 0
Const SCREEN_W = 800
Const SCREEN_H = 600
' load font from incbin:: (be careful with upper/lowercase in the name!)
Incbin "Delicious_00.png"
Incbin "Delicious.fnt"
Local BMF: TBMFont = TBMFont.Create ("incbin::", "Delicious.fnt")
'Incbin "medieval_00.png"
'Incbin "medieval.fnt"
'Local BMF: TBMFont = TBMFont.Create ("incbin::", "medieval.fnt")
' load font with textures from file
'Local BMFArial: TBMFont = TBMFont.Create (CurrentDir() + "/", "Arial.fnt")
Incbin "Arial.fnt"
Incbin "Arial_00.png"
Incbin "Arial_01.png"
Local BMFArial: TBMFont = TBMFont.Create ("incbin::", "Arial.fnt")
' new Type with callback function
Type MyTBMFont Extends TBMFont
Method OnCallBack: Int (Char: Int, X: Float, Y: Float)
If (Char >= Asc ("0")) And (Char <= Asc ("9")) Then
Local f: Float = Sin (2.5 * X + Float (MilliSecs () / 5))
dy = 3.5 * f
SetRotation 2.5 * dy
SetColor($A0 + $3F * f, $B0 + $3F * f, $C0 + $3F * f)
Else
dy = 0
SetRotation 0
SetColor($C0, $C0, $C0)
End If
If Chr (Char) = "<" Then SetColor($FF, $FF, $FF)
If Chr (Char) = ">" Then SetColor($C0, $C0, $C0)
End Method
End Type
Local MyBMF: MyTBMFont = New MyTBMFont
MyBMF.Init ("incbin::", "Delicious.fnt")
Local LastFPS: Int
Local LastMS: Int = MilliSecs ()
Local FPSCounter: Int = 0
Local Shadows: Int = True
Local Kerning: Int = True
AppTitle = "Bitmap Font Demo"
'SetGraphicsDriver GLMax2DDriver () ' OpenGL seems to run much faster than DirectX
Graphics SCREEN_W, SCREEN_H
AutoMidHandle True
Cls
SetScale (0.5, 0.5)
BMF.DrawText ("Generating shadow textures...", 10, 10)
Flip ()
BMF.CreateShadow (2, $C0) ' CreateShadow uses the backbuffer and should be used after Graphics
MyBMF.CreateShadow (1, $80)
BMFArial.CreateShadow (5, $40)
BMFArial.ShadowX = 3
BMFArial.ShadowY = 4
Local BMFTex: TBMFont = TBMFont.Create (CurrentDir() + "/", "tex.fnt")
Local tex: TImage = LoadImage ("texture.png")
BMFTex.ApplyTexture (tex)
SetRotation 45
BMFTex.CreateShadow (3, $80)
SetClsColor $18, $38, $58
SetBlend (ALPHABLEND)
Repeat
Cls
SetBlend (LIGHTBLEND)
'SetBlend (ALPHABLEND)
SeedRnd 0
For Local i = 1 To 500
SetScale (Rnd (1,4), Rnd (1, 4))
SetAlpha (Rnd (1, 5) / 100)
SetRotation Rnd (1, 360)
DrawImage tex, Rnd (0, SCREEN_W), Rnd (0, SCREEN_H)
Next
SetBlend (ALPHABLEND)
SetRotation 0
SetScale 1, 1
FPSCounter :+ 1
Local ms: Int = MilliSecs ()
If ms >= LastMS + 1000 Then
LastFPS = FPSCounter
FPSCounter = 0
LastMS = MilliSecs ()
End If
SetScale (1.0, 1.0)
SetAlpha (1.0)
SetColor ($FF, $FF, $FF)
BMF.ShadowX = 2
BMF.ShadowY = 3
BMF.HSpacing = 2
BMF.VSpacing = 0
BMF.Align = ALIGN_CENTER
BMF.DrawText ("BITMAP FONT DEMO", SCREEN_W / 2, 20)
SetScale (0.6, 0.6)
SetColor ($DF, $EF, $FF)
BMF.ShadowX = 1
BMF.ShadowY = 2
BMF.HSpacing = 1
BMF.VSpacing = -1
BMF.Align = ALIGN_CENTER
BMF.DrawText ("This small demo shows how to use the free wiering.bmfont Bitmap Font module, which is a library~n" + ..
"for using '.fnt' files generated by the AngelCode Bitmap Font Generator. This module supports the~n" + ..
"binary file format '.fnt' files. Textures can have bit depth 8 or 32 (with characters encoded in color~n" + ..
"channels). Kerning is also supported. Press [K] to toggle kerning. Press [S] to toggle shadows.", SCREEN_W / 2, 65)
SetColor ($FF, $FF, $FF)
SetScale (1.0, 1.0)
BMFTex.ShadowX = 3
BMFTex.ShadowY = 4
BMFTex.Align = ALIGN_CENTER
BMFTex.DrawText ("A BITMAP FONT CAN HAVE A TEXTURE,~n" + ..
"WHICH CAN BE LOADED FROM AN IMAGE.", SCREEN_W / 2, 160)
SetScale (0.75, 0.75)
BMFArial.Align = ALIGN_CENTER
BMFArial.Slant = Sin (MilliSecs () / 10) / 3
BMFArial.DrawText ("By setting the Slant property, you can draw italic text~n" + ..
"(Slant only works with DirectX).", SCREEN_W / 2, 250)
BMFArial.Slant = 0
SetColor ($FF, $E0, $80)
SetScale (0.75, 0.55)
BMF.Align = ALIGN_LEFT
BMF.DrawText ("This text is~naligned~nto the left~nAlign = ALIGN_LEFT", 50, 320)
BMF.Align = ALIGN_CENTER
BMF.DrawText ("This~ntext is~ncentered~nAlign = ALIGN_CENTER", SCREEN_W / 2, 320)
BMF.Align = ALIGN_RIGHT
BMF.DrawText ("This text is~naligned~nto the right~nAlign = ALIGN_RIGHT", SCREEN_W - 50, 320)
SetScale (0.7, 0.7)
MyBMF.ShadowX = 2
MyBMF.ShadowY = 3
MyBMF.Align = ALIGN_CENTER
MyBMF.CallBackChars = "<>0123456789"
MyBMF.SkipChars = "<>"
MyBMF.DrawText ("<>By using <callback functions>, you can make your text look even prettier! You can use~n" + ..
"such a function to change the color of the text and <highlight> something for example ...~n" + ..
"~n" + ..
"... or move the characters around: 0 1 2 3 4 5 6 7 8 9~n" + ..
"~n" + ..
"<HAVE FUN!>", SCREEN_W / 2, 420)
SetColor ($FF, $FF, $FF)
SetScale (0.5, 0.5)
SetAlpha (0.5)
BMF.Align = ALIGN_CENTER
BMF.DrawText (LastFPS + " fps, kerning = " + BMF.Kerning + ", shadows = " + Shadows, SCREEN_W / 2, SCREEN_H - 35)
If KeyHit (KEY_K) Then
Kerning = Not Kerning
BMF.Kerning = Kerning
MyBMF.Kerning = Kerning
BMFArial.Kerning = Kerning
BMFTex.Kerning = Kerning
End If
If KeyHit (KEY_S) Then
Shadows = Not Shadows
BMF.Shadow = Shadows
MyBMF.Shadow = Shadows
BMFArial.Shadow = Shadows
BMFTex.Shadow = Shadows
End If
Flip (0)
Until AppTerminate () Or KeyDown (KEY_ESCAPE)