package stb_easy_font // Source port of stb_easy_font.h import "core:math" color :: struct { c: [4]u8, } draw_segs :: proc(x, y: f32, segs: []u8, vertical: bool, c: color, vbuf: []byte, offset: int) -> int { x, y, offset := x, y, offset for i in 0..>31) & 1) if n != 0 && offset+64 <= len(vbuf) { y0 := y + f32(segs[i]>>4) for j in 0..<4 { (^f32)(&vbuf[offset+0])^ = x + ((vertical ? 1 : len) if j==1 || j==2 else 0) (^f32)(&vbuf[offset+4])^ = y0 + ((vertical ? len : 1) if j >= 2 else 0) (^f32)(&vbuf[offset+8])^ = 0 (^color)(&vbuf[offset+12])^ = c offset += 16 } } } return offset } @(private) _spacing_val := f32(0) font_spacing :: proc(spacing: f32) { _spacing_val = spacing } print :: proc(x, y: f32, text: string, color: color, vertex_buffer: []byte) -> int { x, y := x, y text := text start_x := x offset := 0 for len(text) != 0 && offset < len(vertex_buffer) { c := text[0] if c == '\n' { y += 12 x = start_x } else { advance := charinfo[c-32].advance y_ch := y+1 if advance & 16 != 0 else y h_seg := charinfo[c-32].h_seg v_seg := charinfo[c-32].v_seg num_h := charinfo[c-32 + 1].h_seg - h_seg num_v := charinfo[c-32 + 1].v_seg - v_seg offset = draw_segs(x, y_ch, hseg[h_seg:][:num_h], false, color, vertex_buffer, offset) offset = draw_segs(x, y_ch, hseg[v_seg:][:num_v], true, color, vertex_buffer, offset) x += f32(advance & 15) x += _spacing_val } text = text[1:] } return offset/64 } width :: proc(text: string) -> int { length := f32(0) max_length := f32(0) for i in 0.. max_length { max_length = length } length = 0 } else { length += f32(charinfo[c-32].advance & 15) length += _spacing_val } } if length > max_length { max_length = length } return int(math.ceil(max_length)) } height :: proc(text: string) -> int { y := f32(0) nonempty_line := false for i in 0..