annotate examples/E01_hello_triangle.nim @ 652:43240986f76d

add: texture testing, not working yet, something update un-updated descritors (even though we write the descriptors man!)
author Sam <sam@basx.dev>
date Sat, 06 May 2023 01:37:33 +0700
parents 3f13de7d8ec4
children c33c8e156e3e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3f13de7d8ec4 fix: API change for shader attributes
Sam <sam@basx.dev>
parents: 606
diff changeset
6 attr[Vec3f]("position"),
3f13de7d8ec4 fix: API change for shader attributes
Sam <sam@basx.dev>
parents: 606
diff changeset
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()