Mercurial > games > semicongine
annotate examples/E01_hello_triangle.nim @ 336:887ddc8d45fd
did: update examples to work with improved scenegraph/material api, notice removed complexity!
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 05 Sep 2023 00:28:35 +0700 |
parents | f05b4bef44d1 |
children | c66503386e8b |
rev | line source |
---|---|
335 | 1 import std/tables |
2 | |
271 | 3 import ../src/semicongine |
0 | 4 |
335 | 5 # shader setup |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
6 const |
335 | 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;", | |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
15 fragmentCode="color = outcolor;", |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
16 ) |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
17 |
335 | 18 # scene setup |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
19 var |
335 | 20 triangle = Scene(name: "scene", |
21 meshes: @[newMesh( | |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
22 [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], |
210 | 23 [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], |
336
887ddc8d45fd
did: update examples to work with improved scenegraph/material api, notice removed complexity!
Sam <sam@basx.dev>
parents:
335
diff
changeset
|
24 material=Material(name: "default") |
335 | 25 )] |
26 ) | |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
27 myengine = initEngine("Hello triangle") |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
28 |
336
887ddc8d45fd
did: update examples to work with improved scenegraph/material api, notice removed complexity!
Sam <sam@basx.dev>
parents:
335
diff
changeset
|
29 myengine.initRenderer({"default": shaderConfiguration}.toTable) |
335 | 30 myengine.addScene(triangle) |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
31 |
145
a4e6e76128e6
add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents:
136
diff
changeset
|
32 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
33 myengine.renderScene(triangle) |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
34 |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
35 myengine.destroy() |