comparison tests/test_font.nim @ 265:ad4f2b45410b

add: font-test
author Sam <sam@basx.dev>
date Sat, 27 May 2023 13:45:03 +0700
parents
children bfcb41211c5b
comparison
equal deleted inserted replaced
264:dc2304a1bc0a 265:ad4f2b45410b
1 import semicongine
2
3 proc main() =
4 var scene = newScene("main", root=newEntity("rect", rect()))
5 var font = loadFont("DejaVuSans.ttf", "myfont")
6 var img = loadImage("flag.png")
7
8 var textbox = newTextbox(10, 10, font, "Joni")
9 scene.root.add textbox
10
11 var sampler = DefaultSampler()
12 sampler.magnification = VK_FILTER_NEAREST
13 sampler.minification = VK_FILTER_NEAREST
14 scene.addTextures("my_texture", @[
15 Texture(image: img, sampler: sampler)
16 ])
17 scene.addShaderGlobalArray("test2", @[1'f32, 2'f32])
18
19 var engine = initEngine("Test fonts")
20
21 const
22 vertexInput = @[
23 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
24 attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead),
25 ]
26 vertexOutput = @[attr[Vec2f]("uvout")]
27 uniforms = @[attr[float32]("test2", arrayCount=2)]
28 samplers = @[attr[Sampler2DType]("my_texture", arrayCount=1)]
29 fragOutput = @[attr[Vec4f]("color")]
30 vertexCode = compileGlslShader(
31 stage=VK_SHADER_STAGE_VERTEX_BIT,
32 inputs=vertexInput,
33 uniforms=uniforms,
34 samplers=samplers,
35 outputs=vertexOutput,
36 main="""gl_Position = vec4(position, 1.0); uvout = uv;"""
37 )
38 fragmentCode = compileGlslShader(
39 stage=VK_SHADER_STAGE_FRAGMENT_BIT,
40 inputs=vertexOutput,
41 uniforms=uniforms,
42 samplers=samplers,
43 outputs=fragOutput,
44 main="""color = texture(my_texture[0], uvout);"""
45 )
46 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode))
47 engine.addScene(scene, vertexInput, samplers)
48 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
49 engine.renderScene(scene)
50 engine.destroy()
51
52
53 when isMainModule:
54 main()