|
|
@ -1,19 +1,29 @@ |
|
|
|
use std::error::Error;
|
|
|
|
|
|
|
|
use ::{GlyphMetadata, FontAtlas};
|
|
|
|
use ::geometry::{Rect, Vec2};
|
|
|
|
use ::texture::Buffer2d;
|
|
|
|
use ::cache::{CachedFaceData};
|
|
|
|
|
|
|
|
use rusttype::PositionedGlyph;
|
|
|
|
use glium::Program;
|
|
|
|
use glium::backend::Facade;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
struct Vertex {
|
|
|
|
position: [u32; 2],
|
|
|
|
tex_coords: [u32; 2],
|
|
|
|
pub struct Vertex {
|
|
|
|
pub position: [f32; 2],
|
|
|
|
pub tex_coords: [f32; 2],
|
|
|
|
pub color: [f32; 4],
|
|
|
|
}
|
|
|
|
|
|
|
|
implement_vertex!(Vertex, position, tex_coords);
|
|
|
|
implement_vertex!(Vertex, position, tex_coords, color);
|
|
|
|
|
|
|
|
static SHADER_FRAG_140: &'static str = include_str!("gl_renderer_140.frag");
|
|
|
|
static SHADER_VERT_140: &'static str = include_str!("gl_renderer_140.vert");
|
|
|
|
|
|
|
|
pub struct TextRenderer {
|
|
|
|
gl_program: Program,
|
|
|
|
pub gl_program: Program,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TextRenderer {
|
|
|
@ -29,6 +39,72 @@ impl TextRenderer { |
|
|
|
gl_program: program,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn buffers_append_glyph<T>(face: &CachedFaceData<T>, vbo_data: &mut Vec<Vertex>, ibo_data: &mut Vec<u16>,
|
|
|
|
screen_rect: Rect<f32>, metadata: GlyphMetadata, color: [f32; 4])
|
|
|
|
where T: Buffer2d
|
|
|
|
{
|
|
|
|
println!("mbb {:?}", metadata.bounding_box);
|
|
|
|
let texture_bbox: Rect<f32> = metadata.bounding_box.cast();
|
|
|
|
let atlas_dimensions: Vec2<f32> = Vec2::from(face.buffer.dimensions()).cast();
|
|
|
|
// TODO: ugly as shit, fix
|
|
|
|
let texture_bbox_gl = Rect {
|
|
|
|
x: texture_bbox.x / atlas_dimensions.x,
|
|
|
|
y: texture_bbox.y / atlas_dimensions.y,
|
|
|
|
w: texture_bbox.w / atlas_dimensions.x,
|
|
|
|
h: texture_bbox.h / atlas_dimensions.y,
|
|
|
|
};
|
|
|
|
|
|
|
|
println!("texture_bbox: {:?}", texture_bbox);
|
|
|
|
println!("atlas_dimensions: {:?}", atlas_dimensions);
|
|
|
|
println!("texture_bbox_gl: {:?}", texture_bbox_gl);
|
|
|
|
|
|
|
|
|
|
|
|
let vert_offset = vbo_data.len() as u16;
|
|
|
|
ibo_data.push(vert_offset);
|
|
|
|
ibo_data.push(vert_offset + 1);
|
|
|
|
ibo_data.push(vert_offset + 2);
|
|
|
|
ibo_data.push(vert_offset + 2);
|
|
|
|
ibo_data.push(vert_offset + 1);
|
|
|
|
ibo_data.push(vert_offset + 3);
|
|
|
|
|
|
|
|
vbo_data.append(&mut rects_to_verts(&screen_rect, &texture_bbox_gl, color));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn rects_to_verts(screen_rect: &Rect<f32>, texture_rect: &Rect<f32>,
|
|
|
|
color: [f32; 4]) -> Vec<Vertex>
|
|
|
|
{
|
|
|
|
let mut vbo_dat = vec![];
|
|
|
|
|
|
|
|
// upper-left
|
|
|
|
vbo_dat.push(Vertex {
|
|
|
|
position: [screen_rect.left(), screen_rect.top()],
|
|
|
|
tex_coords: [texture_rect.left(), texture_rect.top()],
|
|
|
|
color: color
|
|
|
|
});
|
|
|
|
|
|
|
|
// upper-right
|
|
|
|
vbo_dat.push(Vertex {
|
|
|
|
position: [screen_rect.right(), screen_rect.top()],
|
|
|
|
tex_coords: [texture_rect.right(), texture_rect.top()],
|
|
|
|
color: color
|
|
|
|
});
|
|
|
|
|
|
|
|
// lower-left
|
|
|
|
vbo_dat.push(Vertex {
|
|
|
|
position: [screen_rect.left(), screen_rect.gl_bottom()],
|
|
|
|
tex_coords: [texture_rect.left(), texture_rect.bottom()],
|
|
|
|
color: color
|
|
|
|
});
|
|
|
|
|
|
|
|
// lower-right
|
|
|
|
vbo_dat.push(Vertex {
|
|
|
|
position: [screen_rect.right(), screen_rect.gl_bottom()],
|
|
|
|
tex_coords: [texture_rect.right(), texture_rect.bottom()],
|
|
|
|
color: color
|
|
|
|
});
|
|
|
|
|
|
|
|
// pub fn draw(text: RenderableText)
|
|
|
|
vbo_dat
|
|
|
|
}
|