summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock11
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs29
3 files changed, 29 insertions, 12 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c5bec9f1..c177cf8c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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"
diff --git a/Cargo.toml b/Cargo.toml
index 48a25564..74efab0a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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 {