Mercurial > games > semicongine
annotate examples/E01_hello_triangle.nim @ 1060:b3f782703aa5
did: set correct parameters
author | sam <sam@basx.dev> |
---|---|
date | Mon, 01 Apr 2024 01:05:20 +0700 |
parents | 9c364af8d3f0 |
children | 53249d9bb7a3 |
rev | line source |
---|---|
796 | 1 import std/tables |
2 | |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
3 import ../semicongine |
522
f2c97bdbb0b3
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 |
796 | 5 # shader setup |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
6 const |
796 | 7 shaderConfiguration = createShaderConfiguration( |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
8 inputs = [ |
796 | 9 attr[Vec3f]("position"), |
10 attr[Vec4f]("color"), | |
11 ], | |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
12 intermediates = [attr[Vec4f]("outcolor")], |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
13 outputs = [attr[Vec4f]("color")], |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
14 vertexCode = "gl_Position = vec4(position, 1.0); outcolor = color;", |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
15 fragmentCode = "color = outcolor;", |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
16 ) |
522
f2c97bdbb0b3
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
diff
changeset
|
17 |
796 | 18 # scene setup |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
19 var |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
20 scene = Scene(name: "scene", |
796 | 21 meshes: @[newMesh( |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
22 positions = [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
23 colors = [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
24 material = VERTEX_COLORED_MATERIAL.initMaterialData() |
796 | 25 )] |
26 ) | |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
27 myengine = initEngine("Hello triangle", showFps = true) |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
28 |
1060 | 29 myengine.initRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}, vSync = false, inFlightFrames = 2) |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
30 myengine.loadScene(scene) |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
31 |
606
f41c1b78cf5b
add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents:
597
diff
changeset
|
32 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): |
1059
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
33 transform[Vec3f](scene.meshes[0][], "position", scale(1.001, 1.001)) |
9c364af8d3f0
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
34 myengine.renderScene(scene) |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
35 |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
36 myengine.destroy() |