Mercurial > games > semicongine
annotate examples/E01_hello_triangle.nim @ 271:95281f2db400
did: fix API changes broke examples
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 30 May 2023 16:58:35 +0700 |
parents | ad078e26a1c7 |
children | b17df28712d6 |
rev | line source |
---|---|
271 | 1 import ../src/semicongine |
0 | 2 |
3 | |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
4 const |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
5 vertexInput = @[ |
163 | 6 attr[Vec3f]("position"), |
210 | 7 attr[Vec4f]("color"), |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
8 ] |
210 | 9 vertexOutput = @[attr[Vec4f]("outcolor")] |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
10 fragOutput = @[attr[Vec4f]("color")] |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
11 vertexCode = compileGlslShader( |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
12 stage=VK_SHADER_STAGE_VERTEX_BIT, |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
13 inputs=vertexInput, |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
14 outputs=vertexOutput, |
136
fc5db4f1f94e
did: rewrite example 02 with new engine approach
Sam <sam@basx.dev>
parents:
133
diff
changeset
|
15 main=""" |
fc5db4f1f94e
did: rewrite example 02 with new engine approach
Sam <sam@basx.dev>
parents:
133
diff
changeset
|
16 gl_Position = vec4(position, 1.0); |
fc5db4f1f94e
did: rewrite example 02 with new engine approach
Sam <sam@basx.dev>
parents:
133
diff
changeset
|
17 outcolor = color; |
fc5db4f1f94e
did: rewrite example 02 with new engine approach
Sam <sam@basx.dev>
parents:
133
diff
changeset
|
18 """ |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
19 ) |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
20 fragmentCode = compileGlslShader( |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
21 stage=VK_SHADER_STAGE_FRAGMENT_BIT, |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
22 inputs=vertexOutput, |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
23 outputs=fragOutput, |
210 | 24 main="color = outcolor;" |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
25 ) |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
26 |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
27 var |
203
84fd522fdf3f
did: update examples to use new API for scene + scene globals
Sam <sam@basx.dev>
parents:
163
diff
changeset
|
28 triangle = newScene("scene", newEntity( |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
29 "triangle", |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
30 newMesh( |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
31 [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], |
210 | 32 [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
33 ) |
203
84fd522fdf3f
did: update examples to use new API for scene + scene globals
Sam <sam@basx.dev>
parents:
163
diff
changeset
|
34 )) |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
35 myengine = initEngine("Hello triangle") |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
36 renderPass = myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode) |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
37 |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
38 myengine.setRenderer(renderPass) |
253 | 39 myengine.addScene(triangle, vertexInput, @[]) |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
40 |
145
a4e6e76128e6
add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents:
136
diff
changeset
|
41 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
|
42 myengine.renderScene(triangle) |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
43 |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
44 myengine.destroy() |