Mercurial > games > semicongine
annotate tests/test_materials.nim @ 200:1ba005328615
add: few improvments for working with textures
author | Sam <sam@basx.dev> |
---|---|
date | Sun, 07 May 2023 18:13:39 +0700 |
parents | da68fe12f600 |
children | ab626e67a1ee |
rev | line source |
---|---|
199
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
1 import semicongine |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
2 |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 proc main() = |
da68fe12f600
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())) |
da68fe12f600
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]) |
200
1ba005328615
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
199
diff
changeset
|
6 let (RT, WT, PT) = (hexToColorAlpha("A51931").asPixel, hexToColorAlpha("F4F5F8").asPixel, hexToColorAlpha("2D2A4A").asPixel) |
1ba005328615
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
199
diff
changeset
|
7 scene.addTexture("my_texture", TextureImage(width: 13, height: 5, imagedata: @[ |
1ba005328615
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
199
diff
changeset
|
8 R, R, R, R, R, W, RT, RT, RT, RT, RT, RT, RT, |
1ba005328615
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
199
diff
changeset
|
9 R, R, W, R, R, W, WT, WT, WT, WT, WT, WT, WT, |
1ba005328615
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
199
diff
changeset
|
10 R, W, W, W, R, W, PT, PT, PT, PT, PT, PT, PT, |
1ba005328615
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
199
diff
changeset
|
11 R, R, W, R, R, W, WT, WT, WT, WT, WT, WT, WT, |
1ba005328615
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
199
diff
changeset
|
12 R, R, R, R, R, W, RT, RT, RT, RT, RT, RT, RT, |
199
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
13 ])) |
200
1ba005328615
add: few improvments for working with textures
Sam <sam@basx.dev>
parents:
199
diff
changeset
|
14 var m: Mesh = Mesh(scene.root.components[0]) |
199
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 |
da68fe12f600
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") |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
17 const |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
18 vertexInput = @[ |
da68fe12f600
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), |
da68fe12f600
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), |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
21 ] |
da68fe12f600
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")] |
da68fe12f600
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")] |
da68fe12f600
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")] |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
25 vertexCode = compileGlslShader( |
da68fe12f600
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, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 inputs=vertexInput, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
28 samplers=samplers, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 outputs=vertexOutput, |
da68fe12f600
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;""" |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
31 ) |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 fragmentCode = compileGlslShader( |
da68fe12f600
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, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
34 inputs=vertexOutput, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
35 samplers=samplers, |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
36 outputs=fragOutput, |
da68fe12f600
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);" |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
38 ) |
da68fe12f600
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)) |
da68fe12f600
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) |
da68fe12f600
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): |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
42 engine.renderScene(scene) |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
43 engine.destroy() |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
44 |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
45 |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
46 when isMainModule: |
da68fe12f600
add: new test file to test to do future test with materials etc.
Sam <sam@basx.dev>
parents:
diff
changeset
|
47 main() |