annotate examples/E01_hello_triangle.nim @ 777:754835bf175e

add: changing rendering system, not finished yet, also upgrading to Nim 2
author Sam <sam@basx.dev>
date Mon, 07 Aug 2023 00:23:00 +0700
parents a4c757f5d17f
children 8084252b807a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
732
dcc12ab20a91 did: fix API changes broke examples
Sam <sam@basx.dev>
parents: 714
diff changeset
1 import ../src/semicongine
522
f2c97bdbb0b3 did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
diff changeset
2
f2c97bdbb0b3 did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
diff changeset
3
594
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
4 const
777
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 763
diff changeset
5 inputs = @[
624
3f13de7d8ec4 fix: API change for shader attributes
Sam <sam@basx.dev>
parents: 606
diff changeset
6 attr[Vec3f]("position"),
671
d84b2e88776a fix: always use rgba
Sam <sam@basx.dev>
parents: 664
diff changeset
7 attr[Vec4f]("color"),
594
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
8 ]
777
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 763
diff changeset
9 intermediate = @[attr[Vec4f]("outcolor")]
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 763
diff changeset
10 outputs = @[attr[Vec4f]("color")]
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 763
diff changeset
11 (vertexCode, fragmentCode) = compileVertexFragmentShaderSet(
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 763
diff changeset
12 inputs=inputs,
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 763
diff changeset
13 intermediate=intermediate,
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 763
diff changeset
14 outputs=outputs,
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 763
diff changeset
15 vertexCode="""
597
fdae5f50fa00 did: rewrite example 02 with new engine approach
Sam <sam@basx.dev>
parents: 594
diff changeset
16 gl_Position = vec4(position, 1.0);
fdae5f50fa00 did: rewrite example 02 with new engine approach
Sam <sam@basx.dev>
parents: 594
diff changeset
17 outcolor = color;
777
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 763
diff changeset
18 """,
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 763
diff changeset
19 fragmentCode="color = outcolor;",
594
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
20 )
522
f2c97bdbb0b3 did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
diff changeset
21
594
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
22 var
664
c33c8e156e3e did: update examples to use new API for scene + scene globals
Sam <sam@basx.dev>
parents: 624
diff changeset
23 triangle = newScene("scene", newEntity(
594
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
24 "triangle",
763
a4c757f5d17f did: change API for ECS
Sam <sam@basx.dev>
parents: 739
diff changeset
25 {"mesh": Component(newMesh(
594
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
26 [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
27 [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)],
763
a4c757f5d17f did: change API for ECS
Sam <sam@basx.dev>
parents: 739
diff changeset
28 ))}
664
c33c8e156e3e did: update examples to use new API for scene + scene globals
Sam <sam@basx.dev>
parents: 624
diff changeset
29 ))
594
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
30 myengine = initEngine("Hello triangle")
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
31 renderPass = myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
32
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
33 myengine.setRenderer(renderPass)
777
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 763
diff changeset
34 myengine.addScene(triangle, inputs, @[], transformAttribute="")
594
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
35
606
f41c1b78cf5b add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 597
diff changeset
36 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
37 myengine.renderScene(triangle)
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
38
512d33d314c4 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 535
diff changeset
39 myengine.destroy()