Mercurial > games > semicongine
annotate examples/hello_triangle.nim @ 19:b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 09 Jan 2023 11:04:19 +0700 |
parents | 9e5fe647ff91 |
children | 316923e9247c |
rev | line source |
---|---|
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
1 import zamikongine/engine |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
2 import zamikongine/math/vector |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
3 import zamikongine/vertex |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
4 import zamikongine/mesh |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
5 import zamikongine/thing |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
6 import zamikongine/shader |
0 | 7 |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
8 type |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
9 VertexDataA = object |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
10 position11: VertexAttribute[Vec2[float32]] |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
11 color22: VertexAttribute[Vec3[float32]] |
0 | 12 |
13 when isMainModule: | |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
0
diff
changeset
|
14 var myengine = igniteEngine() |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
15 var mymesh1 = new Mesh[VertexDataA] |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
16 mymesh1.vertexData = VertexDataA( |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
17 position11: VertexAttribute[Vec2[float32]]( |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
18 data: @[ |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
19 Vec2([-0.5'f32, -0.5'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
20 Vec2([ 0.5'f32, 0.5'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
21 Vec2([-0.5'f32, 0.5'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
22 ] |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
23 ), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
24 color22: VertexAttribute[Vec3[float32]]( |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
25 data: @[ |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
26 Vec3([1.0'f32, 1.0'f32, 0.0'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
27 Vec3([0.0'f32, 1.0'f32, 0.0'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
28 Vec3([0.0'f32, 1.0'f32, 1.0'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
29 ] |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
30 ) |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
31 ) |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
32 var mymesh2 = new IndexedMesh[VertexDataA, uint16] |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
33 mymesh2.vertexData = VertexDataA( |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
34 position11: VertexAttribute[Vec2[float32]]( |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
35 data: @[ |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
36 Vec2([ 0.0'f32, -0.7'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
37 Vec2([ 0.6'f32, 0.1'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
38 Vec2([ 0.3'f32, 0.4'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
39 ] |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
40 ), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
41 color22: VertexAttribute[Vec3[float32]]( |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
42 data: @[ |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
43 Vec3([1.0'f32, 1.0'f32, 0.0'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
44 Vec3([1.0'f32, 0.0'f32, 0.0'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
45 Vec3([0.0'f32, 1.0'f32, 1.0'f32]), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
46 ] |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
47 ) |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
48 ) |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
49 mymesh2.indices = @[[0'u16, 1'u16, 2'u16]] |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
50 var athing = new Thing |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
51 athing.parts.add mymesh1 |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
52 var childthing = new Thing |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
53 childthing.parts.add mymesh2 |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
54 athing.children.add childthing |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
55 |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
56 setupPipeline[VertexDataA, uint16]( |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
57 myengine, |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
58 athing, |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
59 generateVertexShaderCode[VertexDataA]("main", "position11", "color22"), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
60 generateFragmentShaderCode[VertexDataA]("main"), |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
61 ) |
0 | 62 myengine.fullThrottle() |
63 myengine.trash() |