Mercurial > games > semicongine
annotate examples/E01_hello_triangle.nim @ 1133:a52e924e5666
add: function to generate circle-mesh data (not mesh object)
author | sam <sam@basx.dev> |
---|---|
date | Sun, 02 Jun 2024 16:21:52 +0700 |
parents | d6c27f0ed3e4 |
children | 71315636ba82 |
rev | line source |
---|---|
796 | 1 import std/tables |
2 | |
950
fe48b091e83f
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( |
1027 | 8 name = "default shader", |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
9 inputs = [ |
796 | 10 attr[Vec3f]("position"), |
11 attr[Vec4f]("color"), | |
12 ], | |
950
fe48b091e83f
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 intermediates = [attr[Vec4f]("outcolor")], |
fe48b091e83f
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 outputs = [attr[Vec4f]("color")], |
fe48b091e83f
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 vertexCode = "gl_Position = vec4(position, 1.0); outcolor = color;", |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
16 fragmentCode = "color = outcolor;", |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
17 ) |
522
f2c97bdbb0b3
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
diff
changeset
|
18 |
796 | 19 # scene setup |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
20 var |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
21 scene = Scene(name: "scene", |
796 | 22 meshes: @[newMesh( |
950
fe48b091e83f
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 positions = [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], |
fe48b091e83f
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 colors = [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
25 material = VERTEX_COLORED_MATERIAL.initMaterialData() |
796 | 26 )] |
27 ) | |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
28 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
|
29 |
957
d27c8dbfef1c
fix: always forget to reset this one when debugging :)
sam <sam@basx.dev>
parents:
956
diff
changeset
|
30 myengine.initRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}, inFlightFrames = 2) |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
31 myengine.loadScene(scene) |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
32 |
1027 | 33 while myengine.UpdateInputs() and not KeyWasPressed(Escape): |
950
fe48b091e83f
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 transform[Vec3f](scene.meshes[0][], "position", scale(1.001, 1.001)) |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
920
diff
changeset
|
35 myengine.renderScene(scene) |
594
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
36 |
512d33d314c4
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
535
diff
changeset
|
37 myengine.destroy() |