Mercurial > games > semicongine
annotate examples/E01_hello_triangle.nim @ 920:c66503386e8b
Merge branch 'main' of github.com:saemideluxe/semicongine
author | Sam <sam@basx.dev> |
---|---|
date | Thu, 21 Mar 2024 15:39:42 +0700 |
parents | 887ddc8d45fd 812b5e28f441 |
children | fe48b091e83f |
rev | line source |
---|---|
796 | 1 import std/tables |
2 | |
732 | 3 import ../src/semicongine |
522
f2c97bdbb0b3
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 |
796 | 5 # shader setup |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
6 const |
796 | 7 shaderConfiguration = createShaderConfiguration( |
8 inputs=[ | |
9 attr[Vec3f]("position"), | |
10 attr[Vec4f]("color"), | |
11 ], | |
12 intermediates=[attr[Vec4f]("outcolor")], | |
13 outputs=[attr[Vec4f]("color")], | |
14 vertexCode="gl_Position = vec4(position, 1.0); outcolor = color;", | |
777
754835bf175e
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
763
diff
changeset
|
15 fragmentCode="color = outcolor;", |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
16 ) |
522
f2c97bdbb0b3
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
diff
changeset
|
17 |
796 | 18 # scene setup |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
19 var |
796 | 20 triangle = Scene(name: "scene", |
21 meshes: @[newMesh( | |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
22 [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], |
671 | 23 [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], |
797
812b5e28f441
did: update examples to work with improved scenegraph/material api, notice removed complexity!
Sam <sam@basx.dev>
parents:
796
diff
changeset
|
24 material=Material(name: "default") |
796 | 25 )] |
26 ) | |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
27 myengine = initEngine("Hello triangle") |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
28 |
797
812b5e28f441
did: update examples to work with improved scenegraph/material api, notice removed complexity!
Sam <sam@basx.dev>
parents:
796
diff
changeset
|
29 myengine.initRenderer({"default": shaderConfiguration}.toTable) |
796 | 30 myengine.addScene(triangle) |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
31 |
606
f41c1b78cf5b
add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents:
597
diff
changeset
|
32 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
33 myengine.renderScene(triangle) |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
34 |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
35 myengine.destroy() |