diff options
author | Joe Wilm <joe@jwilm.com> | 2016-05-20 21:36:28 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-05-20 21:36:28 -0700 |
commit | c70acbac0b721ea2f1b1442898c22aee0f360ef2 (patch) | |
tree | a78722cbabb59c59e7dacc02a4c4d05405839dea /src | |
parent | e794bc11b962adef4d6fbbaeb85344cb138376da (diff) | |
download | alacritty-c70acbac0b721ea2f1b1442898c22aee0f360ef2.tar.gz alacritty-c70acbac0b721ea2f1b1442898c22aee0f360ef2.zip |
Correct sub-pixel font rendering with OpenGL
Uses the GL_ARB_blend_func_extended to get single-pass, per-channel
alpha blending. gl_generator is now used instead of gl to enable the
extension.
The background color is removed since that presumably needs to run in a
separate pass.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 13 | ||||
-rw-r--r-- | src/renderer/mod.rs | 12 | ||||
-rw-r--r-- | src/text.rs | 6 |
3 files changed, 14 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs index 48aaf11b..ef025bea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ extern crate fontconfig; extern crate freetype; extern crate libc; extern crate glutin; -extern crate gl; extern crate cgmath; extern crate euclid; @@ -17,6 +16,10 @@ use renderer::{Glyph, QuadRenderer}; use text::FontDesc; use grid::Grid; +mod gl { + include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs")); +} + static INIT_LIST: &'static str = "abcdefghijklmnopqrstuvwxyz\ ABCDEFGHIJKLMNOPQRSTUVWXYZ\ 01234567890\ @@ -37,7 +40,7 @@ fn main() { let (dpi_x, dpi_y) = window.get_dpi().unwrap(); let dpr = window.hidpi_factor(); - let font_size = 11.0; + let font_size = 11.; let sep_x = 2; let sep_y = 5; @@ -92,8 +95,8 @@ fn main() { } unsafe { - // gl::Enable(gl::BLEND); - // gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); + gl::Enable(gl::BLEND); + gl::BlendFunc(gl::SRC1_COLOR, gl::ONE_MINUS_SRC1_COLOR); gl::Enable(gl::MULTISAMPLE); } @@ -101,7 +104,7 @@ fn main() { for event in window.wait_events() { unsafe { - gl::ClearColor(0.08, 0.08, 0.08, 1.0); + gl::ClearColor(0.0, 0.0, 0.00, 1.0); gl::Clear(gl::COLOR_BUFFER_BIT); } diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 001cb40f..4666981b 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -96,8 +96,7 @@ impl QuadRenderer { self.program.activate(); unsafe { // set color - gl::Uniform3f(self.program.u_color, 1., 1., 0.5); - gl::Uniform3f(self.program.u_bg_color, 0.08, 0.08, 0.08); + gl::Uniform3f(self.program.u_color, 0.917, 0.917, 0.917); } let rect = get_rect(glyph, x, y); @@ -153,8 +152,6 @@ pub struct ShaderProgram { u_projection: GLint, /// color uniform u_color: GLint, - /// background color uniform - u_bg_color: GLint, } impl ShaderProgram { @@ -183,13 +180,11 @@ impl ShaderProgram { // get uniform locations let projection_str = CString::new("projection").unwrap(); let color_str = CString::new("textColor").unwrap(); - let bg_color_str = CString::new("bgColor").unwrap(); - let (projection, color, bg_color) = unsafe { + let (projection, color) = unsafe { ( gl::GetUniformLocation(program, projection_str.as_ptr()), gl::GetUniformLocation(program, color_str.as_ptr()), - gl::GetUniformLocation(program, bg_color_str.as_ptr()), ) }; @@ -197,14 +192,11 @@ impl ShaderProgram { assert!(projection != gl::INVALID_OPERATION as i32); assert!(color != gl::INVALID_VALUE as i32); assert!(color != gl::INVALID_OPERATION as i32); - assert!(bg_color != gl::INVALID_VALUE as i32); - assert!(bg_color != gl::INVALID_OPERATION as i32); let shader = ShaderProgram { id: program, u_projection: projection, u_color: color, - u_bg_color: bg_color, }; // set projection uniform diff --git a/src/text.rs b/src/text.rs index ca414342..0eb08606 100644 --- a/src/text.rs +++ b/src/text.rs @@ -91,8 +91,10 @@ impl Rasterizer { let glyph = face.glyph(); glyph.render_glyph(freetype::render_mode::RenderMode::Lcd).unwrap(); - // FIXME need LCD filtering to reduce color fringes with subpixel rendering. The freetype - // bindings don't currently expose this! + unsafe { + let ft_lib = self.library.raw(); + freetype::ffi::FT_Library_SetLcdFilter(ft_lib, freetype::ffi::FT_LCD_FILTER_LIGHT); + } let bitmap = glyph.bitmap(); let buf = bitmap.buffer(); |