comparison tests/test_materials.nim @ 660:c6414ade79f0

add: new test file to test to do future test with materials etc.
author Sam <sam@basx.dev>
date Sun, 07 May 2023 17:42:53 +0700
parents
children 1ba005328615
comparison
equal deleted inserted replaced
659:8599b84f0563 660:c6414ade79f0
1 import semicongine
2
3 proc main() =
4 var scene = newScene("main", root=newEntity("rect", rect()))
5 let (R, W) = ([255'u8, 0'u8, 0'u8, 255'u8], [255'u8, 255'u8, 255'u8, 255'u8])
6 scene.addTexture("my_texture", TextureImage(width: 5, height: 5, imagedata: @[
7 R, R, R, R, R,
8 R, R, W, R, R,
9 R, W, W, W, R,
10 R, R, W, R, R,
11 R, R, R, R, R,
12 ]))
13
14 var engine = initEngine("Test materials")
15 const
16 vertexInput = @[
17 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
18 attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead),
19 ]
20 vertexOutput = @[attr[Vec2f]("uvout")]
21 samplers = @[attr[Sampler2DType]("my_texture")]
22 fragOutput = @[attr[Vec4f]("color")]
23 vertexCode = compileGlslShader(
24 stage=VK_SHADER_STAGE_VERTEX_BIT,
25 inputs=vertexInput,
26 samplers=samplers,
27 outputs=vertexOutput,
28 main="""gl_Position = vec4(position, 1.0); uvout = uv;"""
29 )
30 fragmentCode = compileGlslShader(
31 stage=VK_SHADER_STAGE_FRAGMENT_BIT,
32 inputs=vertexOutput,
33 samplers=samplers,
34 outputs=fragOutput,
35 main="color = texture(my_texture, uvout);"
36 )
37 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode))
38 engine.addScene(scene, vertexInput)
39 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
40 engine.renderScene(scene)
41 break
42 engine.destroy()
43
44
45 when isMainModule:
46 main()