aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-02-24 19:08:57 -0800
committerJoe Wilm <joe@jwilm.com>2016-02-24 19:08:57 -0800
commit400e4c92a77f875c502847f727cde5f433835b14 (patch)
tree27335adc6cdebbe9d1f60c581018b6bc0fcb800b /src
parent9f8aa9c315c4ac63cbe239b50f51a938b3882435 (diff)
downloadalacritty-400e4c92a77f875c502847f727cde5f433835b14.tar.gz
alacritty-400e4c92a77f875c502847f727cde5f433835b14.zip
build rect describing glyph quad
Diffstat (limited to 'src')
-rw-r--r--src/main.rs29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index 2ba98473..40f36d3a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,15 +4,17 @@ extern crate libc;
extern crate glutin;
extern crate gl;
extern crate cgmath;
+extern crate euclid;
mod list_fonts;
mod text;
-
use std::ffi::CString;
use std::mem::size_of;
use std::ptr;
+use euclid::{Rect, Size2D, Point2D};
+
use libc::c_void;
use gl::types::*;
@@ -90,6 +92,13 @@ fn main() {
}
}
+fn get_rect(glyph: &RasterizedGlyph, x: f32, y: f32) -> Rect<f32> {
+ Rect::new(
+ Point2D::new(x, y),
+ Size2D::new(glyph.width as f32, glyph.height as f32)
+ )
+}
+
/// Render a character
///
/// TODO use element array to describe quad instead
@@ -102,21 +111,17 @@ fn render(program: &ShaderProgram, glyph: &RasterizedGlyph, tex: &AlphaTexture,
gl::Uniform3f(program.color, 1., 1., 0.5);
}
- // bottom left of character
- let left = 10. as f32;
- let bottom = 10. as f32;
+ let rect = get_rect(glyph, 10.0, 10.0);
// top right of character
- let top = bottom + glyph.height as f32;
- let right = left + glyph.width as f32;
let vertices: [[f32; 4]; 6] = [
- [left, top, 0., 0.],
- [left, bottom, 0., 1.],
- [right, bottom, 1., 1.],
+ [rect.min_x(), rect.max_y(), 0., 0.],
+ [rect.min_x(), rect.min_y(), 0., 1.],
+ [rect.max_x(), rect.min_y(), 1., 1.],
- [left, top, 0., 0.],
- [right, bottom, 1., 1.],
- [right, top, 1., 0.],
+ [rect.min_x(), rect.max_y(), 0., 0.],
+ [rect.max_x(), rect.min_y(), 1., 1.],
+ [rect.max_x(), rect.max_y(), 1., 0.],
];
unsafe {