Mercurial > games > semicongine
annotate semiconginev2/text.nim @ 1241:a0ed1a918fda
fix: letters sometimes overlapping other letters quad
author | sam <sam@basx.dev> |
---|---|
date | Mon, 22 Jul 2024 12:51:50 +0700 |
parents | 176383220123 |
children |
rev | line source |
---|---|
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() { | |
1241
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
45 float v = texture(fontAtlas, fragmentUv).r; |
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
46 if(v == 0) { |
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
47 discard; |
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
48 } |
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
49 color = vec4(textbox.color.rgb, textbox.color.a * v); |
1236 | 50 }""" |
1234 | 51 |
52 | |
53 include ./text/font | |
54 include ./text/textbox |