Browse Source

textium: more work on the glium renderer

fuck me i'm not splitting this up
master
Erin 8 years ago
parent
commit
46c037baa0
3 changed files with 93 additions and 10 deletions
  1. +4
    -2
      textium/src/renderer/gl_renderer_140.frag
  2. +7
    -2
      textium/src/renderer/gl_renderer_140.vert
  3. +82
    -6
      textium/src/renderer/glium_renderer.rs

+ 4
- 2
textium/src/renderer/gl_renderer_140.frag View File

@ -1,14 +1,16 @@
#version 140
in vec2 v_tex_coord;
in vec4 v_color;
out vec4 frag_color;
uniform sampler2D tex;
void main() {
vec4 c = vec4(0, 0, 0, texture(tex, v_tex_coord));
frag_color = vec4(texture(tex, v_tex_coord).a, 0, 0, 1);
vec4 c = v_color;
c.a = texture(tex, v_tex_coord).r;
if (c.a <= 0.01) {
discard;
} else {


+ 7
- 2
textium/src/renderer/gl_renderer_140.vert View File

@ -1,12 +1,17 @@
#version 140
in vec2 position;
in vec2 tex_coord;
in vec2 tex_coords;
in vec4 color;
out vec2 v_tex_coord;
out vec4 v_color;
// uniform mat4 matrix;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
v_tex_coord = tex_coord;
v_tex_coord = tex_coords;
v_color = color;
}

+ 82
- 6
textium/src/renderer/glium_renderer.rs View File

@ -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
}

Loading…
Cancel
Save