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
|
1236
|
29 aspectratio: float32
|
1234
|
30 TextboxDescriptorSet = object
|
|
31 textbox: GPUValue[TextboxData, UniformBufferMapped]
|
|
32 fontAtlas: Image[Gray]
|
|
33
|
|
34 DefaultFontShader* = object
|
|
35 position {.VertexAttribute.}: Vec3f
|
|
36 uv {.VertexAttribute.}: Vec2f # TODO: maybe we can keep the uvs in a uniform buffer and just pass an index
|
|
37 fragmentUv {.Pass.}: Vec2f
|
|
38 color {.ShaderOutput.}: Vec4f
|
|
39 descriptorSets {.DescriptorSets.}: (TextboxDescriptorSet, )
|
1236
|
40 vertexCode = """void main() {
|
|
41 gl_Position = vec4(position * vec3(1, textbox.aspectratio, 1) * textbox.scale + textbox.position, 1.0);
|
1234
|
42 fragmentUv = uv;
|
1236
|
43 } """
|
|
44 fragmentCode = """void main() {
|
|
45 color = vec4(textbox.color.rgb, textbox.color.a * texture(fontAtlas, fragmentUv).r);
|
|
46 }"""
|
1234
|
47
|
|
48
|
|
49 include ./text/font
|
|
50 include ./text/textbox
|