Mercurial > games > semicongine
annotate examples/E01_hello_triangle.nim @ 1218:56781cc0fc7c compiletime-tests
did: renamge main package
author | sam <sam@basx.dev> |
---|---|
date | Wed, 17 Jul 2024 21:01:37 +0700 |
parents | 5934c5615f13 |
children |
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 |
1140
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
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 = [ |
1140
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
10 Attr[Vec3f]("position"), |
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
11 Attr[Vec4f]("color"), |
796 | 12 ], |
1140
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
13 intermediates = [Attr[Vec4f]("outcolor")], |
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
14 outputs = [Attr[Vec4f]("color")], |
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
|
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", |
1140
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
22 meshes: @[NewMesh( |
1136 | 23 positions = [NewVec3f(-0.5, 0.5), NewVec3f(0, -0.5), NewVec3f(0.5, 0.5)], |
24 colors = [NewVec4f(1, 0, 0, 1), NewVec4f(0, 1, 0, 1), NewVec4f(0, 0, 1, 1)], | |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
25 material = VERTEX_COLORED_MATERIAL.InitMaterialData() |
796 | 26 )] |
27 ) | |
1140
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
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 |
1140
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
30 myengine.InitRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}, inFlightFrames = 2) |
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
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): |
1140
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
34 Transform[Vec3f](scene.meshes[0][], "position", Scale(1.001, 1.001)) |
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
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 |
1140
5934c5615f13
did: update all examples to work with latest refactoring
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
37 myengine.Destroy() |