annotate examples/E01_hello_triangle.nim @ 1034:d82980c293bb

did: smile, just for the sake of testing mercurial hooks :)
author sam <sam@basx.dev>
date Thu, 21 Mar 2024 15:58:03 +0700
parents c66503386e8b
children fe48b091e83f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
796
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
1 import std/tables
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
2
732
dcc12ab20a91 did: fix API changes broke examples
Sam <sam@basx.dev>
parents: 714
diff changeset
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
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
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
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
7 shaderConfiguration = createShaderConfiguration(
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
8 inputs=[
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
9 attr[Vec3f]("position"),
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
10 attr[Vec4f]("color"),
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
11 ],
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
12 intermediates=[attr[Vec4f]("outcolor")],
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
13 outputs=[attr[Vec4f]("color")],
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
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
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
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
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
20 triangle = Scene(name: "scene",
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
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
d84b2e88776a fix: always use rgba
Sam <sam@basx.dev>
parents: 664
diff changeset
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
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
25 )]
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
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
8084252b807a fix: first example
Sam <sam@basx.dev>
parents: 777
diff changeset
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()