mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -05:00
build rect describing glyph quad
This commit is contained in:
parent
9f8aa9c315
commit
400e4c92a7
3 changed files with 29 additions and 12 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -3,6 +3,7 @@ name = "alacritty"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cgmath 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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)",
|
"glutin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -112,6 +113,16 @@ dependencies = [
|
||||||
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[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]]
|
[[package]]
|
||||||
name = "expat-sys"
|
name = "expat-sys"
|
||||||
version = "2.1.2"
|
version = "2.1.2"
|
||||||
|
|
|
@ -11,3 +11,4 @@ libc = "*"
|
||||||
glutin = "*"
|
glutin = "*"
|
||||||
gl = "*"
|
gl = "*"
|
||||||
cgmath = "0.7"
|
cgmath = "0.7"
|
||||||
|
euclid = "0.6"
|
||||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -4,15 +4,17 @@ extern crate libc;
|
||||||
extern crate glutin;
|
extern crate glutin;
|
||||||
extern crate gl;
|
extern crate gl;
|
||||||
extern crate cgmath;
|
extern crate cgmath;
|
||||||
|
extern crate euclid;
|
||||||
|
|
||||||
mod list_fonts;
|
mod list_fonts;
|
||||||
mod text;
|
mod text;
|
||||||
|
|
||||||
|
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
|
use euclid::{Rect, Size2D, Point2D};
|
||||||
|
|
||||||
use libc::c_void;
|
use libc::c_void;
|
||||||
|
|
||||||
use gl::types::*;
|
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
|
/// Render a character
|
||||||
///
|
///
|
||||||
/// TODO use element array to describe quad instead
|
/// 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);
|
gl::Uniform3f(program.color, 1., 1., 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bottom left of character
|
let rect = get_rect(glyph, 10.0, 10.0);
|
||||||
let left = 10. as f32;
|
|
||||||
let bottom = 10. as f32;
|
|
||||||
|
|
||||||
// top right of character
|
// top right of character
|
||||||
let top = bottom + glyph.height as f32;
|
|
||||||
let right = left + glyph.width as f32;
|
|
||||||
let vertices: [[f32; 4]; 6] = [
|
let vertices: [[f32; 4]; 6] = [
|
||||||
[left, top, 0., 0.],
|
[rect.min_x(), rect.max_y(), 0., 0.],
|
||||||
[left, bottom, 0., 1.],
|
[rect.min_x(), rect.min_y(), 0., 1.],
|
||||||
[right, bottom, 1., 1.],
|
[rect.max_x(), rect.min_y(), 1., 1.],
|
||||||
|
|
||||||
[left, top, 0., 0.],
|
[rect.min_x(), rect.max_y(), 0., 0.],
|
||||||
[right, bottom, 1., 1.],
|
[rect.max_x(), rect.min_y(), 1., 1.],
|
||||||
[right, top, 1., 0.],
|
[rect.max_x(), rect.max_y(), 1., 0.],
|
||||||
];
|
];
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in a new issue