Mercurial > games > semicongine
annotate examples/E01_hello_triangle.nim @ 739:5cd6808150fc
did: adjust for small API change
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 03 Jun 2023 13:44:17 +0700 |
parents | dcc12ab20a91 |
children | a4c757f5d17f |
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 |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
5 vertexInput = @[ |
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 ] |
671 | 9 vertexOutput = @[attr[Vec4f]("outcolor")] |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
10 fragOutput = @[attr[Vec4f]("color")] |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
11 vertexCode = compileGlslShader( |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
12 stage=VK_SHADER_STAGE_VERTEX_BIT, |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
13 inputs=vertexInput, |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
14 outputs=vertexOutput, |
597
fdae5f50fa00
did: rewrite example 02 with new engine approach
Sam <sam@basx.dev>
parents:
594
diff
changeset
|
15 main=""" |
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; |
fdae5f50fa00
did: rewrite example 02 with new engine approach
Sam <sam@basx.dev>
parents:
594
diff
changeset
|
18 """ |
522
f2c97bdbb0b3
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 ) |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
20 fragmentCode = compileGlslShader( |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
21 stage=VK_SHADER_STAGE_FRAGMENT_BIT, |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
22 inputs=vertexOutput, |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
23 outputs=fragOutput, |
671 | 24 main="color = outcolor;" |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
25 ) |
522
f2c97bdbb0b3
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
27 var |
664
c33c8e156e3e
did: update examples to use new API for scene + scene globals
Sam <sam@basx.dev>
parents:
624
diff
changeset
|
28 triangle = newScene("scene", newEntity( |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
29 "triangle", |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
30 newMesh( |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
31 [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], |
671 | 32 [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
33 ) |
664
c33c8e156e3e
did: update examples to use new API for scene + scene globals
Sam <sam@basx.dev>
parents:
624
diff
changeset
|
34 )) |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
35 myengine = initEngine("Hello triangle") |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
36 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
|
37 |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
38 myengine.setRenderer(renderPass) |
739 | 39 myengine.addScene(triangle, vertexInput, @[], transformAttribute="") |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
40 |
606
f41c1b78cf5b
add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents:
597
diff
changeset
|
41 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
|
42 myengine.renderScene(triangle) |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
43 |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
44 myengine.destroy() |