comparison tests/test_font.nim @ 331:05fb85ba97dd

did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
author Sam <sam@basx.dev>
date Sun, 03 Sep 2023 17:34:29 +0700
parents 04531bec3583
children 6cc16b62e497
comparison
equal deleted inserted replaced
330:04531bec3583 331:05fb85ba97dd
5 5
6 proc main() = 6 proc main() =
7 var font = loadFont("DejaVuSans.ttf", color=newVec4f(1, 0.5, 0.5, 1), resolution=20) 7 var font = loadFont("DejaVuSans.ttf", color=newVec4f(1, 0.5, 0.5, 1), resolution=20)
8 8
9 var textbox = initTextbox(32, font, "".toRunes) 9 var textbox = initTextbox(32, font, "".toRunes)
10 var scene = Scene(name: "main", meshes: @[textbox.mesh]) 10 var scene = Scene(name: "main")
11 scene.add textbox
12 textbox.mesh.transform = scale(0.01, 0.01)
11 var engine = initEngine("Test fonts") 13 var engine = initEngine("Test fonts")
12 engine.initRenderer() 14 engine.initRenderer()
15 scene.addShaderGlobal("perspective", Unit4F32)
13 engine.addScene(scene) 16 engine.addScene(scene)
14 scene.addShaderGlobal("perspective", Unit4F32)
15 17
16 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): 18 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
17 if engine.windowWasResized(): 19 if engine.windowWasResized():
18 var winSize = engine.getWindow().size 20 var winSize = engine.getWindow().size
19 scene.setShaderGlobal("perspective", orthoWindowAspect(winSize[1] / winSize[0])) 21 scene.setShaderGlobal("perspective", orthoWindowAspect(winSize[1] / winSize[0]))
22 textbox.mesh.transform = scale(0.01 * (winSize[1] / winSize[0]), 0.01)
20 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]: 23 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]:
21 if engine.keyWasPressed(c): 24 if engine.keyWasPressed(c):
22 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR): 25 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR):
23 textbox.text = textbox.text & ($c).toRunes 26 textbox.text = textbox.text & ($c).toRunes
24 else: 27 else: