Mercurial > games > semicongine
view semiconginev2/text.nim @ 1239:69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
author | sam <sam@basx.dev> |
---|---|
date | Mon, 22 Jul 2024 00:46:10 +0700 |
parents | 176383220123 |
children | a0ed1a918fda |
line wrap: on
line source
const NEWLINE = Rune('\n') SPACE = Rune(' ') type GlyphInfo* = object uvs*: array[4, Vec2f] dimension*: Vec2f topOffset*: float32 leftOffset*: float32 advance*: float32 FontObj* = object name*: string glyphs*: Table[Rune, GlyphInfo] fontAtlas*: Image[Gray] maxHeight*: int kerning*: Table[(Rune, Rune), float32] fontscale*: float32 lineHeight*: float32 lineAdvance*: float32 capHeight*: float32 xHeight*: float32 Font = ref FontObj TextboxData = object color: Vec4f position: Vec3f scale: float32 aspectratio: float32 TextboxDescriptorSet = object textbox: GPUValue[TextboxData, UniformBufferMapped] fontAtlas: Image[Gray] DefaultFontShader* = object position {.VertexAttribute.}: Vec3f uv {.VertexAttribute.}: Vec2f # TODO: maybe we can keep the uvs in a uniform buffer and just pass an index fragmentUv {.Pass.}: Vec2f color {.ShaderOutput.}: Vec4f descriptorSets {.DescriptorSets.}: (TextboxDescriptorSet, ) vertexCode = """void main() { gl_Position = vec4(position * vec3(1, textbox.aspectratio, 1) * textbox.scale + textbox.position, 1.0); fragmentUv = uv; } """ fragmentCode = """void main() { color = vec4(textbox.color.rgb, textbox.color.a * texture(fontAtlas, fragmentUv).r); }""" include ./text/font include ./text/textbox