comparison semiconginev2/text.nim @ 1236:176383220123

add: first font-rendering test
author sam <sam@basx.dev>
date Sat, 20 Jul 2024 17:45:44 +0700
parents 841e12f33c47
children a0ed1a918fda
comparison
equal deleted inserted replaced
1235:c70fee6568f6 1236:176383220123
24 24
25 TextboxData = object 25 TextboxData = object
26 color: Vec4f 26 color: Vec4f
27 position: Vec3f 27 position: Vec3f
28 scale: float32 28 scale: float32
29 aspectratio: float32
29 TextboxDescriptorSet = object 30 TextboxDescriptorSet = object
30 textbox: GPUValue[TextboxData, UniformBufferMapped] 31 textbox: GPUValue[TextboxData, UniformBufferMapped]
31 fontAtlas: Image[Gray] 32 fontAtlas: Image[Gray]
32 33
33 DefaultFontShader* = object 34 DefaultFontShader* = object
34 position {.VertexAttribute.}: Vec3f 35 position {.VertexAttribute.}: Vec3f
35 uv {.VertexAttribute.}: Vec2f # TODO: maybe we can keep the uvs in a uniform buffer and just pass an index 36 uv {.VertexAttribute.}: Vec2f # TODO: maybe we can keep the uvs in a uniform buffer and just pass an index
36 fragmentUv {.Pass.}: Vec2f 37 fragmentUv {.Pass.}: Vec2f
37 color {.ShaderOutput.}: Vec4f 38 color {.ShaderOutput.}: Vec4f
38 descriptorSets {.DescriptorSets.}: (TextboxDescriptorSet, ) 39 descriptorSets {.DescriptorSets.}: (TextboxDescriptorSet, )
39 vertexCode = &""" 40 vertexCode = """void main() {
40 gl_Position = vec4(position * textbox.scale + textbox.position, 1.0); 41 gl_Position = vec4(position * vec3(1, textbox.aspectratio, 1) * textbox.scale + textbox.position, 1.0);
41 fragmentUv = uv; 42 fragmentUv = uv;
42 """ 43 } """
43 fragmentCode = &"""color = vec4(textbox.color.rgb, textbox.color.rgb.a * texture(fontAtlas, fragmentUv).r);""" 44 fragmentCode = """void main() {
45 color = vec4(textbox.color.rgb, textbox.color.a * texture(fontAtlas, fragmentUv).r);
46 }"""
44 47
45 48
46 include ./text/font 49 include ./text/font
47 include ./text/textbox 50 include ./text/textbox