comparison tests/test_text.nim @ 1403:02d302c868d5

fix: font-rendering alignment, still something off with positioning
author sam <sam@basx.dev>
date Wed, 18 Dec 2024 23:39:54 +0700
parents caf441eebc23
children 80cfa19d1e2c
comparison
equal deleted inserted replaced
1402:caf441eebc23 1403:02d302c868d5
16 16
17 type EMPTY = object 17 type EMPTY = object
18 18
19 const MAX_GLYPHS = 200 19 const MAX_GLYPHS = 200
20 proc test_01_static_label_new(time: float32) = 20 proc test_01_static_label_new(time: float32) =
21 var font = loadFont[MAX_GLYPHS]("Overhaul.ttf", lineHeightPixels = 200) 21 # var font = loadFont[MAX_GLYPHS]("Overhaul.ttf", lineHeightPixels = 200)
22 # var font = loadFont[MAX_GLYPHS]("DejaVuSans.ttf", lineHeightPixels = 200) 22 var font = loadFont[MAX_GLYPHS]("DejaVuSans.ttf", lineHeightPixels = 200)
23 var renderdata = initRenderData() 23 var renderdata = initRenderData()
24 var pipeline = 24 var pipeline =
25 createPipeline[GlyphShader[MAX_GLYPHS]](renderPass = vulkan.swapchain.renderPass) 25 createPipeline[GlyphShader[MAX_GLYPHS]](renderPass = vulkan.swapchain.renderPass)
26 var glyphs = font.initGlyphs(1000, baseScale = 0.1) 26 var glyphs = font.initGlyphs(1000, baseScale = 0.1)
27 27
32 32
33 var start = getMonoTime() 33 var start = getMonoTime()
34 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 34 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
35 let t = getMonoTime() 35 let t = getMonoTime()
36 glyphs.reset() 36 glyphs.reset()
37 glyphs.add("semi-\ncon-\nginea", vec3(0.0, 0.0), vec2(0, 0)) 37 glyphs.add("+", vec3(0.0, 0.0), anchor = vec2(0.5, 0.5), color = vec4(0, 0, 0, 1))
38 # glyphs.add("semi-\ncon-\ngine".toRunes(), vec3(0.5, -0.5)) 38 glyphs.add(
39 # glyphs.add("semi-\ncon-\ngine".toRunes(), vec3(-0.5, 0.5)) 39 "Hello world\nHow are you today?\nWell, I am fine".toRunes(),
40 # glyphs.add("semi-\ncon-\ngineb".toRunes(), vec3(0.5, 0.5)) 40 vec3(0.5, 0.5),
41 glyphs.add("semi-\ncon-\ngineb", vec3(0.5, 0.5), vec2(0.5, 0.5)) 41 alignment = Right,
42 glyphs.add("semi-\ncon-\ngineb", vec3(0.9, 0.9), vec2(0, 0)) 42 anchor = vec2(1, 0.5),
43 # glyphs.add("semi-\ncon-\ngineb".toRunes(), vec3(0.1, 0.9)) 43 color = vec4(0, 0, 0, 1),
44 )
45 glyphs.add(
46 "Hello world\nHow are you today?\nWell, I am fine".toRunes(),
47 vec3(0.5, 0.5),
48 alignment = Left,
49 anchor = vec2(0, 0.5),
50 color = vec4(0, 0, 0, 1),
51 )
52 glyphs.add("semi-\ncon-\ngine".toRunes(), vec3(0.5, -0.5), color = vec4(0, 0, 0, 1))
53 glyphs.add("semi-\ncon-\ngine".toRunes(), vec3(-0.5, 0.5), color = vec4(0, 0, 0, 1))
54 # glyphs.add("11111111111111111", vec3(0.5, 0.5), vec2(1, 0))
55 # glyphs.add("22222222222222222", vec3(0.5, 0.5))
56 # glyphs.add("33333333333333333", vec3(0.5, 0.5), vec2(0, 1))
57 glyphs.add("semi-\ncon-\ngineb".toRunes(), vec3(0.1, 0.9), color = vec4(0, 0, 0, 1))
44 glyphs.updateAllGPUBuffers(flush = true) 58 glyphs.updateAllGPUBuffers(flush = true)
45 59
46 withNextFrame(framebuffer, commandbuffer): 60 withNextFrame(framebuffer, commandbuffer):
47 bindDescriptorSet(commandbuffer, font.descriptorSet, 0, pipeline) 61 bindDescriptorSet(commandbuffer, font.descriptorSet, 0, pipeline)
48 withRenderPass( 62 withRenderPass(
49 vulkan.swapchain.renderPass, 63 vulkan.swapchain.renderPass,
50 framebuffer, 64 framebuffer,
51 commandbuffer, 65 commandbuffer,
52 vulkan.swapchain.width, 66 vulkan.swapchain.width,
53 vulkan.swapchain.height, 67 vulkan.swapchain.height,
54 vec4(0, 0, 0, 0), 68 vec4(1, 1, 1, 1),
55 ): 69 ):
56 withPipeline(commandbuffer, pipeline): 70 withPipeline(commandbuffer, pipeline):
57 renderGlyphs(commandbuffer, pipeline, glyphs) 71 renderGlyphs(commandbuffer, pipeline, glyphs)
58 72
59 # cleanup 73 # cleanup