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
use rin_graphics::{Mesh, Vertex2DTex, CoordinateOrigin};
use color::ToRgba;
use glin::RenderSurface;
use super::Renderer;
use glin::gl;
use glin::uniforms;
use rin_math::{vec2, Pnt2, pnt2};


static BMP_CHAR_8X13_MAP:&'static [[i32;15]] = &[
[  8,  0,  0,  0,170,  0,130,  0,130,  0,130,  0,170,  0,  0],
[  8,  0,  0,  0,  0, 16, 56,124,254,124, 56, 16,  0,  0,  0],
[  8,  0,170, 85,170, 85,170, 85,170, 85,170, 85,170, 85,170],
[  8,  0,  0,  0,  4,  4,  4,  4,174,160,224,160,160,  0,  0],
[  8,  0,  0,  0,  8,  8, 12,  8,142,128,192,128,224,  0,  0],
[  8,  0,  0,  0, 10, 10, 12, 10,108,128,128,128, 96,  0,  0],
[  8,  0,  0,  0,  8,  8, 12,  8,238,128,128,128,128,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0, 24, 36, 36, 24,  0,  0],
[  8,  0,  0,  0,  0,124,  0, 16, 16,124, 16, 16,  0,  0,  0],
[  8,  0,  0,  0, 14,  8,  8,  8,168,160,160,160,192,  0,  0],
[  8,  0,  0,  0,  4,  4,  4,  4, 46, 80, 80,136,136,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,240, 16, 16, 16, 16, 16, 16],
[  8,  0, 16, 16, 16, 16, 16, 16,240,  0,  0,  0,  0,  0,  0],
[  8,  0, 16, 16, 16, 16, 16, 16, 31,  0,  0,  0,  0,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0, 31, 16, 16, 16, 16, 16, 16],
[  8,  0, 16, 16, 16, 16, 16, 16,255, 16, 16, 16, 16, 16, 16],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,255],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,255,  0,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,255,  0,  0,  0,  0,  0,  0],
[  8,  0,  0,  0,  0,255,  0,  0,  0,  0,  0,  0,  0,  0,  0],
[  8,  0,255,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
[  8,  0, 16, 16, 16, 16, 16, 16, 31, 16, 16, 16, 16, 16, 16],
[  8,  0, 16, 16, 16, 16, 16, 16,240, 16, 16, 16, 16, 16, 16],
[  8,  0,  0,  0,  0,  0,  0,  0,255, 16, 16, 16, 16, 16, 16],
[  8,  0, 16, 16, 16, 16, 16, 16,255,  0,  0,  0,  0,  0,  0],
[  8,  0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16],
[  8,  0,  0,  0,254,  0, 14, 48,192, 48, 14,  0,  0,  0,  0],
[  8,  0,  0,  0,254,  0,224, 24,  6, 24,224,  0,  0,  0,  0],
[  8,  0,  0,  0, 68, 68, 68, 68, 68,254,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 32, 32,126, 16,  8,126,  4,  4,  0,  0,  0],
[  8,  0,  0,  0,220, 98, 32, 32, 32,112, 32, 34, 28,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0, 24,  0,  0,  0,  0,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 16,  0, 16, 16, 16, 16, 16, 16, 16,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0, 36, 36, 36,  0,  0],
[  8,  0,  0,  0,  0, 36, 36,126, 36,126, 36, 36,  0,  0,  0],
[  8,  0,  0,  0, 16,120, 20, 20, 56, 80, 80, 60, 16,  0,  0],
[  8,  0,  0,  0, 68, 42, 36, 16,  8,  8, 36, 82, 34,  0,  0],
[  8,  0,  0,  0, 58, 68, 74, 48, 72, 72, 48,  0,  0,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0, 64, 48, 56,  0,  0],
[  8,  0,  0,  0,  4,  8,  8, 16, 16, 16,  8,  8,  4,  0,  0],
[  8,  0,  0,  0, 32, 16, 16,  8,  8,  8, 16, 16, 32,  0,  0],
[  8,  0,  0,  0,  0,  0, 36, 24,126, 24, 36,  0,  0,  0,  0],
[  8,  0,  0,  0,  0,  0, 16, 16,124, 16, 16,  0,  0,  0,  0],
[  8,  0,  0, 64, 48, 56,  0,  0,  0,  0,  0,  0,  0,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,126,  0,  0,  0,  0,  0,  0],
[  8,  0,  0, 16, 56, 16,  0,  0,  0,  0,  0,  0,  0,  0,  0],
[  8,  0,  0,  0,128,128, 64, 32, 16,  8,  4,  2,  2,  0,  0],
[  8,  0,  0,  0, 24, 36, 66, 66, 66, 66, 66, 36, 24,  0,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 16, 80, 48, 16,  0,  0],
[  8,  0,  0,  0,126, 64, 32, 24,  4,  2, 66, 66, 60,  0,  0],
[  8,  0,  0,  0, 60, 66,  2,  2, 28,  8,  4,  2,126,  0,  0],
[  8,  0,  0,  0,  4,  4,126, 68, 68, 36, 20, 12,  4,  0,  0],
[  8,  0,  0,  0, 60, 66,  2,  2, 98, 92, 64, 64,126,  0,  0],
[  8,  0,  0,  0, 60, 66, 66, 98, 92, 64, 64, 32, 28,  0,  0],
[  8,  0,  0,  0, 32, 32, 16, 16,  8,  8,  4,  2,126,  0,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 60, 66, 66, 66, 60,  0,  0],
[  8,  0,  0,  0, 56,  4,  2,  2, 58, 70, 66, 66, 60,  0,  0],
[  8,  0,  0, 16, 56, 16,  0,  0, 16, 56, 16,  0,  0,  0,  0],
[  8,  0,  0, 64, 48, 56,  0,  0, 16, 56, 16,  0,  0,  0,  0],
[  8,  0,  0,  0,  2,  4,  8, 16, 32, 16,  8,  4,  2,  0,  0],
[  8,  0,  0,  0,  0,  0,126,  0,  0,126,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 64, 32, 16,  8,  4,  8, 16, 32, 64,  0,  0],
[  8,  0,  0,  0,  8,  0,  8,  8,  4,  2, 66, 66, 60,  0,  0],
[  8,  0,  0,  0, 60, 64, 74, 86, 82, 78, 66, 66, 60,  0,  0],
[  8,  0,  0,  0, 66, 66, 66,126, 66, 66, 66, 36, 24,  0,  0],
[  8,  0,  0,  0,252, 66, 66, 66,124, 66, 66, 66,252,  0,  0],
[  8,  0,  0,  0, 60, 66, 64, 64, 64, 64, 64, 66, 60,  0,  0],
[  8,  0,  0,  0,252, 66, 66, 66, 66, 66, 66, 66,252,  0,  0],
[  8,  0,  0,  0,126, 64, 64, 64,120, 64, 64, 64,126,  0,  0],
[  8,  0,  0,  0, 64, 64, 64, 64,120, 64, 64, 64,126,  0,  0],
[  8,  0,  0,  0, 58, 70, 66, 78, 64, 64, 64, 66, 60,  0,  0],
[  8,  0,  0,  0, 66, 66, 66, 66,126, 66, 66, 66, 66,  0,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 16, 16, 16,124,  0,  0],
[  8,  0,  0,  0, 56, 68,  4,  4,  4,  4,  4,  4, 31,  0,  0],
[  8,  0,  0,  0, 66, 68, 72, 80, 96, 80, 72, 68, 66,  0,  0],
[  8,  0,  0,  0,126, 64, 64, 64, 64, 64, 64, 64, 64,  0,  0],
[  8,  0,  0,  0,130,130,130,146,146,170,198,130,130,  0,  0],
[  8,  0,  0,  0, 66, 66, 66, 70, 74, 82, 98, 66, 66,  0,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 66, 66, 66, 60,  0,  0],
[  8,  0,  0,  0, 64, 64, 64, 64,124, 66, 66, 66,124,  0,  0],
[  8,  0,  0,  2, 60, 74, 82, 66, 66, 66, 66, 66, 60,  0,  0],
[  8,  0,  0,  0, 66, 68, 72, 80,124, 66, 66, 66,124,  0,  0],
[  8,  0,  0,  0, 60, 66,  2,  2, 60, 64, 64, 66, 60,  0,  0],
[  8,  0,  0,  0, 16, 16, 16, 16, 16, 16, 16, 16,254,  0,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 66, 66, 66, 66,  0,  0],
[  8,  0,  0,  0, 16, 40, 40, 40, 68, 68, 68,130,130,  0,  0],
[  8,  0,  0,  0, 68,170,146,146,146,130,130,130,130,  0,  0],
[  8,  0,  0,  0,130,130, 68, 40, 16, 40, 68,130,130,  0,  0],
[  8,  0,  0,  0, 16, 16, 16, 16, 16, 40, 68,130,130,  0,  0],
[  8,  0,  0,  0,126, 64, 64, 32, 16,  8,  4,  2,126,  0,  0],
[  8,  0,  0,  0, 60, 32, 32, 32, 32, 32, 32, 32, 60,  0,  0],
[  8,  0,  0,  0,  2,  2,  4,  8, 16, 32, 64,128,128,  0,  0],
[  8,  0,  0,  0,120,  8,  8,  8,  8,  8,  8,  8,120,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0, 68, 40, 16,  0,  0],
[  8,  0,  0,254,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0,  4, 24, 56,  0,  0],
[  8,  0,  0,  0, 58, 70, 66, 62,  2, 60,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 92, 98, 66, 66, 98, 92, 64, 64, 64,  0,  0],
[  8,  0,  0,  0, 60, 66, 64, 64, 66, 60,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 58, 70, 66, 66, 70, 58,  2,  2,  2,  0,  0],
[  8,  0,  0,  0, 60, 66, 64,126, 66, 60,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 32, 32, 32, 32,124, 32, 32, 34, 28,  0,  0],
[  8,  0, 60, 66, 60, 64, 56, 68, 68, 58,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 66, 66, 66, 66, 98, 92, 64, 64, 64,  0,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 48,  0, 16,  0,  0,  0],
[  8,  0, 56, 68, 68,  4,  4,  4,  4, 12,  0,  4,  0,  0,  0],
[  8,  0,  0,  0, 66, 68, 72,112, 72, 68, 64, 64, 64,  0,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 16, 16, 16, 48,  0,  0],
[  8,  0,  0,  0,130,146,146,146,146,236,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 66, 66, 66, 66, 98, 92,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 60,  0,  0,  0,  0,  0],
[  8,  0, 64, 64, 64, 92, 98, 66, 98, 92,  0,  0,  0,  0,  0],
[  8,  0,  2,  2,  2, 58, 70, 66, 70, 58,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 32, 32, 32, 32, 34, 92,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 60, 66, 12, 48, 66, 60,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 28, 34, 32, 32, 32,124, 32, 32,  0,  0,  0],
[  8,  0,  0,  0, 58, 68, 68, 68, 68, 68,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 16, 40, 40, 68, 68, 68,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 68,170,146,146,130,130,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 66, 36, 24, 24, 36, 66,  0,  0,  0,  0,  0],
[  8,  0, 60, 66,  2, 58, 70, 66, 66, 66,  0,  0,  0,  0,  0],
[  8,  0,  0,  0,126, 32, 16,  8,  4,126,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 14, 16, 16,  8, 48,  8, 16, 16, 14,  0,  0],
[  8,  0,  0,  0, 16, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0],
[  8,  0,  0,  0,112,  8,  8, 16, 12, 16,  8,  8,112,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0, 72, 84, 36,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  9,  0,  0,  0,  0,  0,  0,170,  0,  0,  0,130,  0,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 16, 16, 16, 16, 16, 16, 16,  0, 16,  0,  0],
[  8,  0,  0,  0,  0, 16, 56, 84, 80, 80, 84, 56, 16,  0,  0],
[  8,  0,  0,  0,220, 98, 32, 32, 32,112, 32, 34, 28,  0,  0],
[  8,  0,  0,  0,  0, 66, 60, 36, 36, 60, 66,  0,  0,  0,  0],
[  8,  0,  0,  0, 16, 16,124, 16,124, 40, 68,130,130,  0,  0],
[  8,  0,  0,  0, 16, 16, 16, 16,  0, 16, 16, 16, 16,  0,  0],
[  8,  0,  0,  0, 24, 36,  4, 24, 36, 36, 24, 32, 36, 24,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,108,  0,  0],
[  8,  0,  0,  0,  0, 56, 68,146,170,162,170,146, 68, 56,  0],
[  8,  0,  0,  0,  0,  0,124,  0, 60, 68, 60,  4, 56,  0,  0],
[  8,  0,  0,  0,  0, 18, 36, 72,144, 72, 36, 18,  0,  0,  0],
[  8,  0,  0,  0,  0,  2,  2,  2,126,  0,  0,  0,  0,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0, 60,  0,  0,  0,  0,  0,  0],
[  8,  0,  0,  0,  0, 56, 68,170,178,170,170,146, 68, 56,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,126,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0, 24, 36, 36, 24,  0,  0],
[  8,  0,  0,  0,  0,124,  0, 16, 16,124, 16, 16,  0,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,120, 64, 48,  8, 72, 48,  0],
[  8,  0,  0,  0,  0,  0,  0,  0, 48, 72,  8, 16, 72, 48,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16,  8,  0],
[  8,  0,  0, 64, 90,102, 66, 66, 66, 66,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 20, 20, 20, 20, 52,116,116,116, 62,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0, 24,  0,  0,  0,  0,  0,  0],
[  8,  0, 24,  8,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
[  8,  0,  0,  0,  0,  0,  0,  0,112, 32, 32, 32, 96, 32,  0],
[  8,  0,  0,  0,  0,  0,  0,120,  0, 48, 72, 72, 48,  0,  0],
[  8,  0,  0,  0,  0,144, 72, 36, 18, 36, 72,144,  0,  0,  0],
[  8,  0,  0,  0,  6, 26, 18, 10,230, 66, 64, 64,192, 64,  0],
[  8,  0,  0,  0, 30, 16, 12,  2,242, 76, 64, 64,192, 64,  0],
[  8,  0,  0,  0,  6, 26, 18, 10,102,146, 16, 32,144, 96,  0],
[  8,  0,  0,  0, 60, 66, 66, 64, 32, 16, 16,  0, 16,  0,  0],
[  8,  0,  0,  0, 66, 66,126, 66, 66, 36, 24,  0,  8, 16,  0],
[  8,  0,  0,  0, 66, 66,126, 66, 66, 36, 24,  0, 16,  8,  0],
[  8,  0,  0,  0, 66, 66,126, 66, 66, 36, 24,  0, 36, 24,  0],
[  8,  0,  0,  0, 66, 66,126, 66, 66, 36, 24,  0, 76, 50,  0],
[  8,  0,  0,  0, 66, 66,126, 66, 66, 36, 24,  0, 36, 36,  0],
[  8,  0,  0,  0, 66, 66,126, 66, 66, 36, 24, 24, 36, 24,  0],
[  8,  0,  0,  0,158,144,144,240,156,144,144,144,110,  0,  0],
[  8,  0, 16,  8, 60, 66, 64, 64, 64, 64, 64, 66, 60,  0,  0],
[  8,  0,  0,  0,126, 64, 64,120, 64, 64,126,  0,  8, 16,  0],
[  8,  0,  0,  0,126, 64, 64,120, 64, 64,126,  0, 16,  8,  0],
[  8,  0,  0,  0,126, 64, 64,120, 64, 64,126,  0, 36, 24,  0],
[  8,  0,  0,  0,126, 64, 64,120, 64, 64,126,  0, 36, 36,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 16,124,  0, 16, 32,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 16,124,  0, 16,  8,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 16,124,  0, 36, 24,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 16,124,  0, 40, 40,  0],
[  8,  0,  0,  0,120, 68, 66, 66,226, 66, 66, 68,120,  0,  0],
[  8,  0,  0,  0,130,134,138,146,162,194,130,  0,152,100,  0],
[  8,  0,  0,  0,124,130,130,130,130,130,124,  0, 16, 32,  0],
[  8,  0,  0,  0,124,130,130,130,130,130,124,  0, 16,  8,  0],
[  8,  0,  0,  0,124,130,130,130,130,130,124,  0, 36, 24,  0],
[  8,  0,  0,  0,124,130,130,130,130,130,124,  0,152,100,  0],
[  8,  0,  0,  0,124,130,130,130,130,130,124,  0, 40, 40,  0],
[  8,  0,  0,  0,  0, 66, 36, 24, 24, 36, 66,  0,  0,  0,  0],
[  8,  0,  0, 64, 60, 98, 82, 82, 82, 74, 74, 70, 60,  2,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 66, 66,  0,  8, 16,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 66, 66,  0, 16,  8,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 66, 66,  0, 36, 24,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 66, 66,  0, 36, 36,  0],
[  8,  0,  0,  0, 16, 16, 16, 16, 40, 68, 68,  0, 16,  8,  0],
[  8,  0,  0,  0, 64, 64, 64,124, 66, 66, 66,124, 64,  0,  0],
[  8,  0,  0,  0, 92, 66, 66, 76, 80, 72, 68, 68, 56,  0,  0],
[  8,  0,  0,  0, 58, 70, 66, 62,  2, 60,  0,  0,  8, 16,  0],
[  8,  0,  0,  0, 58, 70, 66, 62,  2, 60,  0,  0,  8,  4,  0],
[  8,  0,  0,  0, 58, 70, 66, 62,  2, 60,  0,  0, 36, 24,  0],
[  8,  0,  0,  0, 58, 70, 66, 62,  2, 60,  0,  0, 76, 50,  0],
[  8,  0,  0,  0, 58, 70, 66, 62,  2, 60,  0,  0, 36, 36,  0],
[  8,  0,  0,  0, 58, 70, 66, 62,  2, 60,  0, 24, 36, 24,  0],
[  8,  0,  0,  0,108,146,144,124, 18,108,  0,  0,  0,  0,  0],
[  8,  0, 16,  8, 60, 66, 64, 64, 66, 60,  0,  0,  0,  0,  0],
[  8,  0,  0,  0, 60, 66, 64,126, 66, 60,  0,  0,  8, 16,  0],
[  8,  0,  0,  0, 60, 66, 64,126, 66, 60,  0,  0, 16,  8,  0],
[  8,  0,  0,  0, 60, 66, 64,126, 66, 60,  0,  0, 36, 24,  0],
[  8,  0,  0,  0, 60, 66, 64,126, 66, 60,  0,  0, 36, 36,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 48,  0,  0, 16, 32,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 48,  0,  0, 32, 16,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 48,  0,  0, 72, 48,  0],
[  8,  0,  0,  0,124, 16, 16, 16, 16, 48,  0,  0, 40, 40,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 60,  4, 40, 24, 36,  0],
[  8,  0,  0,  0, 66, 66, 66, 66, 98, 92,  0,  0, 76, 50,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 60,  0,  0, 16, 32,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 60,  0,  0, 16,  8,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 60,  0,  0, 36, 24,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 60,  0,  0, 76, 50,  0],
[  8,  0,  0,  0, 60, 66, 66, 66, 66, 60,  0,  0, 36, 36,  0],
[  8,  0,  0,  0,  0, 16, 16,  0,124,  0, 16, 16,  0,  0,  0],
[  8,  0,  0, 64, 60, 98, 82, 74, 70, 60,  2,  0,  0,  0,  0],
[  8,  0,  0,  0, 58, 68, 68, 68, 68, 68,  0,  0, 16, 32,  0],
[  8,  0,  0,  0, 58, 68, 68, 68, 68, 68,  0,  0, 16,  8,  0],
[  8,  0,  0,  0, 58, 68, 68, 68, 68, 68,  0,  0, 36, 24,  0],
[  8,  0,  0,  0, 58, 68, 68, 68, 68, 68,  0,  0, 40, 40,  0],
[  8,  0, 60, 66,  2, 58, 70, 66, 66, 66,  0,  0, 16,  8,  0],
[  8,  0, 64, 64, 92, 98, 66, 66, 98, 92, 64, 64,  0,  0,  0],
[  8,  0, 60, 66,  2, 58, 70, 66, 66, 66,  0,  0, 36, 36,  0]
];

/// Usually not to be used directly but internally by rin to
/// draw_bitmap_string from a renderer
pub struct BitmapFont{
    texture: glin::Texture,
    char_w: f32,
    char_h: f32,
}

impl BitmapFont{
    // #[cfg(not(feature = "gles"))]
    pub(crate) fn new(gl: &glin::Context) -> BitmapFont{
        let mut tex = gl.new_texture()
            .from_format(glin::texture::Format::new(gl::R8, 16*16, 16*16))
            .unwrap();

        let mut pixels = vec![0u8;16*16*16*16];

        for i in 0 .. 256 {
            let face = &BMP_CHAR_8X13_MAP[i];
            for j in 1 .. 15{
                for k in 0 .. 8 {
                    if  ((face[15-j] << k) & (128)) > 0 {
                        pixels[((i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k] = 255;
                    }else{
                        pixels[((i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k] = 0;
                    }
                }
            }
        }

        tex.load_data(&pixels, Default::default()).unwrap();
        tex.set_min_mag_filters(gl::LINEAR, gl::NEAREST);


        BitmapFont{
            texture: tex,
            char_w: 8.0f32/256.0f32,
            char_h: 14.0f32/256.0f32,
        }
    }

    fn add_char(c: char, pos: &Pnt2, mesh: &mut Mesh<Vertex2DTex>, num_verts: usize, char_w: f32, char_h: f32, coordinate_origin: CoordinateOrigin){
        if c < (128u8 as char) {
            let tex_w = (((c as u8) % 16) as f32)/16.0f32;
            let tex_h = ((c as i32 as f32 / 16.0f32) as i32) as f32/16.0f32;

            let y1 = tex_h;
            let y2 = tex_h + char_h;

            let offset = match coordinate_origin{
				CoordinateOrigin::BottomLeft | CoordinateOrigin::CenterUp => 14.0,
				CoordinateOrigin::TopLeft | CoordinateOrigin::CenterDown => -14.0,
			};
            let pos_y = match coordinate_origin{
				CoordinateOrigin::BottomLeft | CoordinateOrigin::CenterUp => pos.y + 5.0,
				CoordinateOrigin::TopLeft | CoordinateOrigin::CenterDown => pos.y + 11.0,
			};

            mesh.get_mut(num_verts).texcoord =   vec2(tex_w, y2);
            mesh.get_mut(num_verts+1).texcoord = vec2(tex_w + char_w, y2);
            mesh.get_mut(num_verts+2).texcoord = vec2(tex_w + char_w, y1);

            mesh.get_mut(num_verts+3).texcoord = vec2(tex_w + char_w, y1);
            mesh.get_mut(num_verts+4).texcoord = vec2(tex_w, y1);
            mesh.get_mut(num_verts+5).texcoord = vec2(tex_w, y2);

            mesh.get_mut(num_verts).position =   vec2(pos.x, pos_y);
            mesh.get_mut(num_verts+1).position = vec2(pos.x+8.0, pos_y);
            mesh.get_mut(num_verts+2).position = vec2(pos.x+8.0, pos_y+offset);

            mesh.get_mut(num_verts+3).position = vec2(pos.x+8.0, pos_y+offset);
            mesh.get_mut(num_verts+4).position = vec2(pos.x, pos_y+offset);
            mesh.get_mut(num_verts+5).position = vec2(pos.x, pos_y);
        }
    }

    /// Returns the mesh with texture coordinates to draw a string with this font
    pub fn mesh(&self, string: &str, pos: &Pnt2, coordinate_origin: CoordinateOrigin) -> Mesh<Vertex2DTex>{
        let mut mesh = Mesh::default();
        mesh.reserve(6 * string.len());
        unsafe{
            mesh.set_len(6 * string.len());
        }
        let mut num_verts = 0;
        let font_size = 8.0f32;
        let mut sx = pos.x as f32;
        let mut sy = pos.y as f32 - font_size;
        let line_height = font_size*1.7f32;
        let new_line_direction = 1.0f32;
        let mut column = 0;


        for c in string.chars(){
            if c == '\n'{
                sy += line_height*new_line_direction;
                sx = pos.x as f32;
                column = 0;
            } else if c == '\t'{
                let out = column + 8 - (column % 8);
                sx += font_size * ((out-column) as f32);
                column = out;
            } else if c >= (32u8 as char){
                BitmapFont::add_char(c,
                    &pnt2(sx, sy),
                    &mut mesh,
                    num_verts,
                    self.char_w,
                    self.char_h,
                    coordinate_origin);
                num_verts += 6;
                sx += font_size;
                column+=1;
            }
        }

        if num_verts > 0 {
            mesh.truncate(num_verts);
        }

        mesh
    }

    /// Returns the font texture atlas
    pub fn texture(&self) -> &glin::Texture{
        &self.texture
    }

    /// Returns a material that can be used to draw a mesh with this font
	pub fn material<C: ToRgba>(&self, color: &C) -> Material{
		Material{
			uniforms: uniforms!{
	        	color: color.to_rgba::<f32>(),
	        	src_tex_unit0: self.texture
			},
		}
	}
}

/// Material to draw a bitmap font
pub struct Material{
    uniforms: Vec<glin::program::Uniform>,
}

impl super::Material for Material{
    fn program<R: RenderSurface>(&self, renderer: &Renderer<R>) -> &glin::Program{
        &shaders::get_program(renderer)
    }

    fn uniforms<R: RenderSurface>(&self, _renderer: &Renderer<R>) -> &[glin::program::Uniform]{
        &self.uniforms
    }

    fn properties(&self) -> &[glin::Property]{
        &[
            glin::Property::Blend(true),
            glin::Property::BlendFuncSeparate(
                gl::SRC_ALPHA,
                gl::ONE_MINUS_SRC_ALPHA,
                gl::ONE,
                gl::ONE_MINUS_SRC_ALPHA,
            )
        ]
    }
}

#[cfg(not(any(feature = "gles", feature="webgl")))]
mod shaders{
    program_cache!("shaders/vertex_bitmap_font.glsl", "shaders/fragment_bitmap_font.glsl");
}

#[cfg(any(feature = "gles", feature="webgl"))]
mod shaders{
    program_cache!("shaders/vertex_bitmap_font_gles.glsl", "shaders/fragment_bitmap_font_gles.glsl");
}