Skip to content

Instantly share code, notes, and snippets.

@Papierkorb
Created October 5, 2017 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Papierkorb/ca6e8ae4e4aee2eb2c085655f96d8916 to your computer and use it in GitHub Desktop.
Save Papierkorb/ca6e8ae4e4aee2eb2c085655f96d8916 to your computer and use it in GitHub Desktop.
private def build_vertices : Array(Vertex)
vertices = [ ] of Vertex
texture_size = @font.texture_for(@size).size
baseline = 0
@lines.each do |line|
baseline += line.top
colors = @formatter.format(line.text, @default_color)
build_line_vertices(vertices, line, colors, baseline, texture_size)
end
vertices
end
# Inner loop split into own function.
private def build_line_vertices(vertices, line, colors, baseline, texture_size)
prev_glyph = nil
advance = 0
line.glyphs.zip(colors) do |glyph, color|
kerning = 0 # Ternary Conditions always have the issue of "wtf is the else? .. ah there it is *scroll*"
kerning = @font.get_kerning(prev_glyph.code, glyph.code, @size) if prev_glyph
create_glyph_vertices(vertices, glyph, color, advance, baseline, texture_size)
advance += glyph.advance + kerning
prev_glyph = glyph
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment