对于多个字符 Freetype/OpenGL,Advance x 不正确?

问题描述

这是我使用 opengl 渲染文本时得到的(我的在右边)

enter image description here

字母“j”非常接近字母“k”

这是我测量字符大小和位置的方法

fn main() {
    let library = ft::Library::init().unwrap();
    let face = library.new_face(font,0).unwrap();

    face.set_pixel_sizes(0,50);

    let string = String::from("jkl");

    let mut font_measure: HashMap<char,FontSize> = HashMap::new();

    for c in string.chars() {
        face.load_char(c as usize,ft::face::LoadFlag::DEFAULT)
            .unwrap();

        let glyph = face.glyph();
        let metrics = glyph.metrics();
        let width = metrics.width >> 6;
        let bBox_ymax = face.raw().bBox.yMax >> 6;
        let face_height = (face.raw().height >> 6) as f64;

        font_measure.insert(
            c,FontSize {
                width: metrics.width >> 6,height: metrics.height >> 6,advance: glyph.advance().x + width / 2 >> 6,y_offset: (bBox_ymax - metrics.horibearingY >> 6) as f64 + face_height,},);
    }
}
fn main() {
    let mut pen_x = 0.0;
    let mut pen_y = 0.0;
    for character in line.text.chars() {
        let character_props = &k.get(&character).unwrap();
        
        // ....
        // vertex_buffer.splice(start..end,character_vertices.iter().cloned());

        // move drawing position in the x for advance.x
        pen_x += character_props.advance;
    }
}

解决方法

解决了。我没有考虑水平方向

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...