Mercurial > games > semicongine
view semiconginev2/text.nim @ 1258:5442d0e9d8ff
did: improve testing lighting, try new glb model (need to add jpeg support first)
author | sam <sam@basx.dev> |
---|---|
date | Sun, 28 Jul 2024 20:42:51 +0700 |
parents | a0ed1a918fda |
children |
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() { float v = texture(fontAtlas, fragmentUv).r; if(v == 0) { discard; } color = vec4(textbox.color.rgb, textbox.color.a * v); }""" include ./text/font include ./text/textbox