Mercurial > games > semicongine
comparison tests/test_materials.nim @ 272:bfcb41211c5b
add: final font-rendering, API changes fixed
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 30 May 2023 16:59:01 +0700 |
parents | ad078e26a1c7 |
children | da0bd61abe91 |
comparison
equal
deleted
inserted
replaced
271:95281f2db400 | 272:bfcb41211c5b |
---|---|
1 import std/times | 1 import std/times |
2 import std/tables | |
2 | 3 |
3 import semicongine | 4 import semicongine |
4 | 5 |
5 proc main() = | 6 proc main() = |
6 var scene = newScene("main", root=newEntity("rect", rect())) | 7 var scene = newScene("main", root=newEntity("rect", rect())) |
19 t2 = loadImage("flag.png") | 20 t2 = loadImage("flag.png") |
20 | 21 |
21 var sampler = DefaultSampler() | 22 var sampler = DefaultSampler() |
22 sampler.magnification = VK_FILTER_NEAREST | 23 sampler.magnification = VK_FILTER_NEAREST |
23 sampler.minification = VK_FILTER_NEAREST | 24 sampler.minification = VK_FILTER_NEAREST |
24 scene.addTextures("my_texture", @[Texture(image: t1, sampler: sampler), Texture(image: t2, sampler: sampler)]) | 25 scene.addMaterial(Material(name:"my material", textures: {"my_texture": Texture(image: t1, sampler: sampler)}.toTable)) |
26 scene.addMaterial(Material(name:"my material", textures: {"my_texture": Texture(image: t2, sampler: sampler)}.toTable)) | |
25 scene.addShaderGlobalArray("test2", @[0'f32, 0'f32]) | 27 scene.addShaderGlobalArray("test2", @[0'f32, 0'f32]) |
26 | 28 |
27 var engine = initEngine("Test materials") | 29 var engine = initEngine("Test materials") |
28 | 30 |
29 const | 31 const |
53 float d = sin(Uniforms.test2[0]) * 0.5 + 0.5; | 55 float d = sin(Uniforms.test2[0]) * 0.5 + 0.5; |
54 color = texture(my_texture[0], uvout) * (1 - d) + texture(my_texture[1], uvout) * d; | 56 color = texture(my_texture[0], uvout) * (1 - d) + texture(my_texture[1], uvout) * d; |
55 """ | 57 """ |
56 ) | 58 ) |
57 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) | 59 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) |
58 engine.addScene(scene, vertexInput, samplers) | 60 engine.addScene(scene, vertexInput, samplers, transformAttribute="") |
59 var t = cpuTime() | 61 var t = cpuTime() |
60 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): | 62 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
61 var d = float32(cpuTime() - t) | 63 var d = float32(cpuTime() - t) |
62 setShaderGlobalArray(scene, "test2", @[d, d * 2]) | 64 setShaderGlobalArray(scene, "test2", @[d, d * 2]) |
63 engine.renderScene(scene) | 65 engine.renderScene(scene) |