1234
|
1 const
|
|
2 NEWLINE = Rune('\n')
|
|
3 SPACE = Rune(' ')
|
|
4
|
|
5 type
|
|
6 GlyphInfo* = object
|
|
7 uvs*: array[4, Vec2f]
|
|
8 dimension*: Vec2f
|
|
9 topOffset*: float32
|
|
10 leftOffset*: float32
|
|
11 advance*: float32
|
|
12 FontObj* = object
|
|
13 name*: string
|
|
14 glyphs*: Table[Rune, GlyphInfo]
|
|
15 fontAtlas*: Image[Gray]
|
|
16 maxHeight*: int
|
|
17 kerning*: Table[(Rune, Rune), float32]
|
|
18 fontscale*: float32
|
|
19 lineHeight*: float32
|
|
20 lineAdvance*: float32
|
|
21 capHeight*: float32
|
|
22 xHeight*: float32
|
|
23 Font = ref FontObj
|
|
24
|
|
25 TextboxData = object
|
|
26 color: Vec4f
|
|
27 position: Vec3f
|
|
28 scale: float32
|
|
29 TextboxDescriptorSet = object
|
|
30 textbox: GPUValue[TextboxData, UniformBufferMapped]
|
|
31 fontAtlas: Image[Gray]
|
|
32
|
|
33 DefaultFontShader* = object
|
|
34 position {.VertexAttribute.}: Vec3f
|
|
35 uv {.VertexAttribute.}: Vec2f # TODO: maybe we can keep the uvs in a uniform buffer and just pass an index
|
|
36 fragmentUv {.Pass.}: Vec2f
|
|
37 color {.ShaderOutput.}: Vec4f
|
|
38 descriptorSets {.DescriptorSets.}: (TextboxDescriptorSet, )
|
|
39 vertexCode = &"""
|
|
40 gl_Position = vec4(position * textbox.scale + textbox.position, 1.0);
|
|
41 fragmentUv = uv;
|
|
42 """
|
|
43 fragmentCode = &"""color = vec4(textbox.color.rgb, textbox.color.rgb.a * texture(fontAtlas, fragmentUv).r);"""
|
|
44
|
|
45
|
|
46 include ./text/font
|
|
47 include ./text/textbox
|