diff tests/test_font.nim @ 872:1ee397815b0b

did: image & font refactoring, add texture-atlas-packing
author Sam <sam@basx.dev>
date Sat, 20 Jan 2024 20:17:03 +0700
parents 388c4b35a6e3
children 262e771e2573
line wrap: on
line diff
--- a/tests/test_font.nim	Mon Jan 08 19:18:01 2024 +0700
+++ b/tests/test_font.nim	Sat Jan 20 20:17:03 2024 +0700
@@ -9,16 +9,18 @@
 
   # build scene
   var scene = Scene(name: "main")
-  var font = loadFont("DejaVuSans.ttf", color=newVec4f(1, 0.5, 0.5, 1), resolution=20)
-  var textbox = initTextbox(32, font, "")
+  # var font = loadFont("DejaVuSans.ttf", lineHeightPixels=90'f32, charset="abcdefghijklmnopqrstuvwxyz ".toRunes)
+  var font = loadFont("DejaVuSans.ttf", lineHeightPixels=90'f32)
+  var textbox = initText(32, font, "", color=newVec4f(1, 0, 0, 1))
+  let fontscale = 0.005
   scene.add textbox
-  textbox.mesh.transform = scale(0.01, 0.01)
+  textbox.mesh.transform = scale(fontscale, fontscale)
   engine.loadScene(scene)
 
   while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
     if engine.windowWasResized():
       var winSize = engine.getWindow().size
-      textbox.mesh.transform = scale(0.01 * (winSize[1] / winSize[0]), 0.01)
+      textbox.mesh.transform = scale(fontscale * (winSize[1] / winSize[0]), fontscale)
     for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z]:
       if engine.keyWasPressed(c):
         if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR):