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