# HG changeset patch # User sam # Date 1723885755 -25200 # Node ID ad09d41abd1e96e1c80777235c953fb46ac5fa42 # Parent a53a31b6e027194b796d002eaf05804599ea5da4 add: 2d-scaling for text diff -r a53a31b6e027 -r ad09d41abd1e semicongine/rendering/renderer.nim --- a/semicongine/rendering/renderer.nim Sat Aug 17 15:09:01 2024 +0700 +++ b/semicongine/rendering/renderer.nim Sat Aug 17 16:09:15 2024 +0700 @@ -685,7 +685,7 @@ layout = pipeline.layout, stageFlags = VkShaderStageFlags(VK_SHADER_STAGE_ALL_GRAPHICS), offset = 0, - size = PUSH_CONSTANT_SIZE, + size = sizeof(pushConstant).uint32, pValues = addr(pushConstant) ); render(commandBuffer, pipeline, mesh, instances, fixedVertexCount) @@ -702,7 +702,7 @@ layout = pipeline.layout, stageFlags = VkShaderStageFlags(VK_SHADER_STAGE_ALL_GRAPHICS), offset = 0, - size = PUSH_CONSTANT_SIZE, + size = sizeof(pushConstant).uint32, pValues = addr(pushConstant) ); render(commandBuffer, pipeline, mesh, EMPTY(), fixedVertexCount) diff -r a53a31b6e027 -r ad09d41abd1e semicongine/text.nim --- a/semicongine/text.nim Sat Aug 17 15:09:01 2024 +0700 +++ b/semicongine/text.nim Sat Aug 17 16:09:15 2024 +0700 @@ -42,7 +42,8 @@ TextboxData = object color: Vec4f position: Vec3f - scale: float32 + tmp: float32 + scale: Vec2f DefaultFontShader*[T] = object position {.VertexAttribute.}: Vec3f @@ -52,11 +53,12 @@ textbox {.PushConstant.}: TextboxData descriptorSets {.DescriptorSet: 0.}: T vertexCode* = """void main() { - gl_Position = vec4(position * textbox.scale + textbox.position, 1.0); + gl_Position = vec4(position * vec3(textbox.scale, 1) + textbox.position, 1.0); fragmentUv = uv; } """ fragmentCode* = """void main() { float v = texture(fontAtlas, fragmentUv).r; + // CARFULL: This can lead to rough edges at times if(v == 0) { discard; } diff -r a53a31b6e027 -r ad09d41abd1e semicongine/text/textbox.nim --- a/semicongine/text/textbox.nim Sat Aug 17 15:09:01 2024 +0700 +++ b/semicongine/text/textbox.nim Sat Aug 17 16:09:15 2024 +0700 @@ -140,7 +140,7 @@ textbox: Textbox, position: Vec3f, color: Vec4f, - scale: float32 = 1, + scale: Vec2f = vec2(1, 1), ) = renderWithPushConstant( commandbuffer = commandbuffer, diff -r a53a31b6e027 -r ad09d41abd1e tests/test_text.nim --- a/tests/test_text.nim Sat Aug 17 15:09:01 2024 +0700 +++ b/tests/test_text.nim Sat Aug 17 16:09:15 2024 +0700 @@ -213,11 +213,11 @@ var labels: seq[Textbox] var positions = newSeq[Vec3f](100) var colors = newSeq[Vec4f](100) - var scales = newSeq[float32](100) + var scales = newSeq[Vec2f](100) for i in 0 ..< 100: positions[i] = vec3(rand(-0.5 .. 0.5), rand(-0.5 .. 0.5), rand(-0.1 .. 0.1)) colors[i] = vec4(rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0)) - scales[i] = rand(0.5'f32 .. 1.5'f32) + scales[i] = vec2(rand(0.5'f32 .. 1.5'f32), rand(0.5'f32 .. 1.5'f32)) labels.add initTextbox( renderdata, pipeline.layout(0),