changeset 1329:ad09d41abd1e

add: 2d-scaling for text
author sam <sam@basx.dev>
date Sat, 17 Aug 2024 16:09:15 +0700
parents a53a31b6e027
children b165359f45d7
files semicongine/rendering/renderer.nim semicongine/text.nim semicongine/text/textbox.nim tests/test_text.nim
diffstat 4 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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;
     }
--- 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,
--- 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),