Mercurial > games > semicongine
annotate examples/E01_hello_triangle.nim @ 789:fca6f069d59e
did: some cleanup
author | Sam <sam@basx.dev> |
---|---|
date | Fri, 25 Aug 2023 01:14:04 +0700 |
parents | 754835bf175e |
children | 8084252b807a |
rev | line source |
---|---|
732 | 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 | 6 attr[Vec3f]("position"), |
671 | 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 | 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 | 27 [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], |
763 | 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() |