Mercurial > games > semicongine
comparison 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 |
comparison
equal
deleted
inserted
replaced
199:da68fe12f600 | 200:1ba005328615 |
---|---|
1 import semicongine | 1 import semicongine |
2 | 2 |
3 proc main() = | 3 proc main() = |
4 var scene = newScene("main", root=newEntity("rect", rect())) | 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]) | 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: @[ | 6 let (RT, WT, PT) = (hexToColorAlpha("A51931").asPixel, hexToColorAlpha("F4F5F8").asPixel, hexToColorAlpha("2D2A4A").asPixel) |
7 R, R, R, R, R, | 7 scene.addTexture("my_texture", TextureImage(width: 13, height: 5, imagedata: @[ |
8 R, R, W, R, R, | 8 R, R, R, R, R, W, RT, RT, RT, RT, RT, RT, RT, |
9 R, W, W, W, R, | 9 R, R, W, R, R, W, WT, WT, WT, WT, WT, WT, WT, |
10 R, R, W, R, R, | 10 R, W, W, W, R, W, PT, PT, PT, PT, PT, PT, PT, |
11 R, R, R, R, R, | 11 R, R, W, R, R, W, WT, WT, WT, WT, WT, WT, WT, |
12 R, R, R, R, R, W, RT, RT, RT, RT, RT, RT, RT, | |
12 ])) | 13 ])) |
14 var m: Mesh = Mesh(scene.root.components[0]) | |
13 | 15 |
14 var engine = initEngine("Test materials") | 16 var engine = initEngine("Test materials") |
15 const | 17 const |
16 vertexInput = @[ | 18 vertexInput = @[ |
17 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), | 19 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
36 ) | 38 ) |
37 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) | 39 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) |
38 engine.addScene(scene, vertexInput) | 40 engine.addScene(scene, vertexInput) |
39 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): | 41 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
40 engine.renderScene(scene) | 42 engine.renderScene(scene) |
41 break | |
42 engine.destroy() | 43 engine.destroy() |
43 | 44 |
44 | 45 |
45 when isMainModule: | 46 when isMainModule: |
46 main() | 47 main() |