Mercurial > games > semicongine
annotate examples/E01_hello_triangle.nim @ 626:bf2f4a9cd962
add: option to show/hide cursor
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 29 Apr 2023 21:38:52 +0700 |
parents | 3f13de7d8ec4 |
children | c33c8e156e3e |
rev | line source |
---|---|
522
f2c97bdbb0b3
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
diff
changeset
|
1 import semicongine |
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"), |
7 attr[Vec3f]("color"), | |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
8 ] |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
9 vertexOutput = @[attr[Vec3f]("outcolor")] |
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, |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
24 main="color = vec4(outcolor, 1);" |
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 |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
28 triangle = newEntity( |
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)], |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
32 [X, Y, Z], |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
33 ) |
522
f2c97bdbb0b3
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
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) |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
39 myengine.addScene(triangle, vertexInput) |
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() |