diff options
author | Joe Wilm <joe@jwilm.com> | 2016-02-24 19:08:57 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-02-24 19:08:57 -0800 |
commit | 400e4c92a77f875c502847f727cde5f433835b14 (patch) | |
tree | 27335adc6cdebbe9d1f60c581018b6bc0fcb800b | |
parent | 9f8aa9c315c4ac63cbe239b50f51a938b3882435 (diff) | |
download | r-alacritty-400e4c92a77f875c502847f727cde5f433835b14.tar.gz r-alacritty-400e4c92a77f875c502847f727cde5f433835b14.tar.bz2 r-alacritty-400e4c92a77f875c502847f727cde5f433835b14.zip |
build rect describing glyph quad
-rw-r--r-- | Cargo.lock | 11 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 29 |
3 files changed, 29 insertions, 12 deletions
@@ -3,6 +3,7 @@ name = "alacritty" version = "0.1.0" dependencies = [ "cgmath 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "freetype-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gl 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -113,6 +114,16 @@ dependencies = [ ] [[package]] +name = "euclid" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "expat-sys" version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -11,3 +11,4 @@ libc = "*" glutin = "*" gl = "*" cgmath = "0.7" +euclid = "0.6" 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 { |