Mercurial > games > semicongine
annotate tests/test_materials.nim @ 661:9995702c34b2
add: few improvments for working with textures
author | Sam <sam@basx.dev> |
---|---|
date | Sun, 07 May 2023 18:13:39 +0700 |
parents | c6414ade79f0 |
children | ab626e67a1ee |
rev | line source |
---|---|
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
1 import semicongine |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
2 |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 proc main() = |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 var scene = newScene("main", root=newEntity("rect", rect())) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 let (R, W) = ([255'u8, 0'u8, 0'u8, 255'u8], [255'u8, 255'u8, 255'u8, 255'u8]) |
661
9995702c34b2
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
660
diff
changeset
|
6 let (RT, WT, PT) = (hexToColorAlpha("A51931").asPixel, hexToColorAlpha("F4F5F8").asPixel, hexToColorAlpha("2D2A4A").asPixel) |
9995702c34b2
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
660
diff
changeset
|
7 scene.addTexture("my_texture", TextureImage(width: 13, height: 5, imagedata: @[ |
9995702c34b2
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
660
diff
changeset
|
8 R, R, R, R, R, W, RT, RT, RT, RT, RT, RT, RT, |
9995702c34b2
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
660
diff
changeset
|
9 R, R, W, R, R, W, WT, WT, WT, WT, WT, WT, WT, |
9995702c34b2
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
660
diff
changeset
|
10 R, W, W, W, R, W, PT, PT, PT, PT, PT, PT, PT, |
9995702c34b2
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
660
diff
changeset
|
11 R, R, W, R, R, W, WT, WT, WT, WT, WT, WT, WT, |
9995702c34b2
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
660
diff
changeset
|
12 R, R, R, R, R, W, RT, RT, RT, RT, RT, RT, RT, |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
13 ])) |
661
9995702c34b2
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
660
diff
changeset
|
14 var m: Mesh = Mesh(scene.root.components[0]) |
660
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
16 var engine = initEngine("Test materials") |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
17 const |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
18 vertexInput = @[ |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
20 attr[Vec2f]("uv", memoryPerformanceHint=PreferFastRead), |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
21 ] |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
22 vertexOutput = @[attr[Vec2f]("uvout")] |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
23 samplers = @[attr[Sampler2DType]("my_texture")] |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
24 fragOutput = @[attr[Vec4f]("color")] |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
25 vertexCode = compileGlslShader( |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 stage=VK_SHADER_STAGE_VERTEX_BIT, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 inputs=vertexInput, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
28 samplers=samplers, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 outputs=vertexOutput, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
30 main="""gl_Position = vec4(position, 1.0); uvout = uv;""" |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
31 ) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 fragmentCode = compileGlslShader( |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
33 stage=VK_SHADER_STAGE_FRAGMENT_BIT, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
34 inputs=vertexOutput, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
35 samplers=samplers, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
36 outputs=fragOutput, |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 main="color = texture(my_texture, uvout);" |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
38 ) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
39 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
40 engine.addScene(scene, vertexInput) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
41 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
42 engine.renderScene(scene) |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
43 engine.destroy() |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
44 |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
45 |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
46 when isMainModule: |
c6414ade79f0
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
47 main() |