Mercurial > games > semicongine
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_font.nim Sat May 27 13:45:03 2023 +0700 @@ -0,0 +1,54 @@ +import semicongine + +proc main() = + var scene = newScene("main", root=newEntity("rect", rect())) + var font = loadFont("DejaVuSans.ttf", "myfont") + var img = loadImage("flag.png") + + var textbox = newTextbox(10, 10, font, "Joni") + scene.root.add textbox + + var sampler = DefaultSampler() + sampler.magnification = VK_FILTER_NEAREST + sampler.minification = VK_FILTER_NEAREST + scene.addTextures("my_texture", @[ + Texture(image: img, sampler: sampler) + ]) + scene.addShaderGlobalArray("test2", @[1'f32, 2'f32]) + + var engine = initEngine("Test fonts") + + const + vertexInput = @[ + attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), + attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead), + ] + vertexOutput = @[attr[Vec2f]("uvout")] + uniforms = @[attr[float32]("test2", arrayCount=2)] + samplers = @[attr[Sampler2DType]("my_texture", arrayCount=1)] + fragOutput = @[attr[Vec4f]("color")] + vertexCode = compileGlslShader( + stage=VK_SHADER_STAGE_VERTEX_BIT, + inputs=vertexInput, + uniforms=uniforms, + samplers=samplers, + outputs=vertexOutput, + main="""gl_Position = vec4(position, 1.0); uvout = uv;""" + ) + fragmentCode = compileGlslShader( + stage=VK_SHADER_STAGE_FRAGMENT_BIT, + inputs=vertexOutput, + uniforms=uniforms, + samplers=samplers, + outputs=fragOutput, + main="""color = texture(my_texture[0], uvout);""" + ) + engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) + engine.addScene(scene, vertexInput, samplers) + while engine.updateInputs() == Running and not engine.keyIsDown(Escape): + engine.renderScene(scene) + engine.destroy() + + +when isMainModule: + main()