Mercurial > games > semicongine
comparison semicongine/text.nim @ 1327:373a4888f6ac
did: rework font-rendering
author | sam <sam@basx.dev> |
---|---|
date | Sat, 17 Aug 2024 13:54:22 +0700 |
parents | 4a1c2b1128bc |
children | ad09d41abd1e |
comparison
equal
deleted
inserted
replaced
1326:41f3612ef38d | 1327:373a4888f6ac |
---|---|
41 | 41 |
42 TextboxData = object | 42 TextboxData = object |
43 color: Vec4f | 43 color: Vec4f |
44 position: Vec3f | 44 position: Vec3f |
45 scale: float32 | 45 scale: float32 |
46 aspectratio: float32 | |
47 TextboxDescriptorSet = object | |
48 textbox: GPUValue[TextboxData, UniformBufferMapped] | |
49 fontAtlas: Image[Gray] | |
50 | 46 |
51 DefaultFontShader* = object | 47 DefaultFontShader*[T] = object |
52 position {.VertexAttribute.}: Vec3f | 48 position {.VertexAttribute.}: Vec3f |
53 uv {.VertexAttribute.}: Vec2f # TODO: maybe we can keep the uvs in a uniform buffer and just pass an index | 49 uv {.VertexAttribute.}: Vec2f # TODO: maybe we can keep the uvs in a uniform buffer and just pass an index |
54 fragmentUv {.Pass.}: Vec2f | 50 fragmentUv {.Pass.}: Vec2f |
55 color {.ShaderOutput.}: Vec4f | 51 color {.ShaderOutput.}: Vec4f |
56 descriptorSets {.DescriptorSet: 0.}: TextboxDescriptorSet | 52 textbox {.PushConstant.}: TextboxData |
53 descriptorSets {.DescriptorSet: 0.}: T | |
57 vertexCode* = """void main() { | 54 vertexCode* = """void main() { |
58 gl_Position = vec4(position * vec3(1 / textbox.aspectratio, 1, 1) * textbox.scale + textbox.position, 1.0); | 55 gl_Position = vec4(position * textbox.scale + textbox.position, 1.0); |
59 fragmentUv = uv; | 56 fragmentUv = uv; |
60 } """ | 57 } """ |
61 fragmentCode* = """void main() { | 58 fragmentCode* = """void main() { |
62 float v = texture(fontAtlas, fragmentUv).r; | 59 float v = texture(fontAtlas, fragmentUv).r; |
63 if(v == 0) { | 60 if(v == 0) { |
64 discard; | 61 discard; |
65 } | 62 } |
66 color = vec4(textbox.color.rgb, textbox.color.a * v); | 63 color = vec4(textbox.color.rgb, textbox.color.a * v); |
67 }""" | 64 }""" |
68 | 65 |
66 proc `=copy`(dest: var FontObj; source: FontObj) {.error.} | |
69 | 67 |
70 include ./text/font | 68 include ./text/font |
71 include ./text/textbox | 69 include ./text/textbox |