changeset 1237:97813ac43cfb

add: multi-text with all properties animated
author sam <sam@basx.dev>
date Sun, 21 Jul 2024 00:03:48 +0700
parents 176383220123
children 03634915bbdb
files tests/test_text.nim
diffstat 1 files changed, 66 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test_text.nim	Sat Jul 20 17:45:44 2024 +0700
+++ b/tests/test_text.nim	Sun Jul 21 00:03:48 2024 +0700
@@ -10,10 +10,6 @@
 proc test_01_static_label(time: float32, swapchain: var Swapchain) =
   var renderdata = InitRenderData()
 
-  # scale: float32 = 1,
-  # position: Vec3f = NewVec3f(),
-  # color: Vec4f = NewVec4f(0, 0, 0, 1),
-
   var pipeline = CreatePipeline[DefaultFontShader](renderPass = swapchain.renderPass)
 
   var font = LoadFont("Overhaul.ttf", lineHeightPixels = 160)
@@ -39,6 +35,70 @@
   DestroyPipeline(pipeline)
   DestroyRenderData(renderdata)
 
+proc test_02_multiple_animated(time: float32, swapchain: var Swapchain) =
+  var renderdata = InitRenderData()
+
+  var pipeline = CreatePipeline[DefaultFontShader](renderPass = swapchain.renderPass)
+
+  var font1 = LoadFont("Overhaul.ttf", lineHeightPixels = 40)
+  var font2 = LoadFont("Overhaul.ttf", lineHeightPixels = 160)
+  var font3 = LoadFont("DejaVuSans.ttf", lineHeightPixels = 160)
+  var labels = [
+    InitTextbox(
+      renderdata,
+      pipeline.descriptorSetLayouts[0],
+      font1,
+      "0",
+      color = NewVec4f(0, 1, 1, 1),
+      scale = 0.004,
+      position = NewVec3f(-0.3, 0.5)
+    ),
+    InitTextbox(
+      renderdata,
+      pipeline.descriptorSetLayouts[0],
+      font2,
+      "1",
+      color = NewVec4f(1, 0, 1, 1),
+      scale = 0.001,
+      position = NewVec3f(0, 0)
+    ),
+    InitTextbox(
+      renderdata,
+      pipeline.descriptorSetLayouts[0],
+      font3,
+      "2",
+      color = NewVec4f(1, 1, 0, 1),
+      scale = 0.001,
+      position = NewVec3f(0.3, -0.5)
+    )
+  ]
+
+  var start = getMonoTime()
+  while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
+    let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time
+    for i in 0 ..< labels.len:
+      var c = labels[i].Color
+      c[i] = progress
+      labels[i].Color = c
+      labels[i].Scale = labels[i].Scale * 1.002
+      labels[i].Position = labels[i].Position + NewVec3f(0.001 * (i.float - 1'f))
+      labels[i].Refresh(swapchain.GetAspectRatio())
+    WithNextFrame(swapchain, framebuffer, commandbuffer):
+      WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
+        WithPipeline(commandbuffer, pipeline):
+          for label in labels:
+            Render(label, commandbuffer, pipeline, swapchain.currentFiF)
+
+        # cleanup
+  checkVkResult vkDeviceWaitIdle(vulkan.device)
+  DestroyPipeline(pipeline)
+  DestroyRenderData(renderdata)
+
+proc test_03_layouting(time: float32, swapchain: var Swapchain) =
+  discard # TODO
+proc test_04_lots_of_texts(time: float32, swapchain: var Swapchain) =
+  discard # TODO
+
 when isMainModule:
   var time = 10'f32
   InitVulkan()
@@ -47,7 +107,8 @@
   var swapchain = InitSwapchain(renderpass = renderpass).get()
 
   # tests a simple triangle with minimalistic shader and vertex format
-  test_01_static_label(time, swapchain)
+  # test_01_static_label(time, swapchain)
+  test_02_multiple_animated(time, swapchain)
 
   checkVkResult vkDeviceWaitIdle(vulkan.device)
   vkDestroyRenderPass(vulkan.device, renderpass.vk, nil)