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]
];
pub struct BitmapFont{
texture: glin::Texture,
char_w: f32,
char_h: f32,
}
impl BitmapFont{
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);
}
}
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
}
pub fn texture(&self) -> &glin::Texture{
&self.texture
}
pub fn material<C: ToRgba>(&self, color: &C) -> Material{
Material{
uniforms: uniforms!{
color: color.to_rgba::<f32>(),
src_tex_unit0: self.texture
},
}
}
}
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");
}