comparison 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
comparison
equal deleted inserted replaced
479:16842d15319a 480:14e5151f68d1
1 import engine 1 import zamikongine/engine
2 import zamikongine/math/vector
3 import zamikongine/vertex
4 import zamikongine/mesh
5 import zamikongine/thing
6 import zamikongine/shader
2 7
8 type
9 VertexDataA = object
10 position11: VertexAttribute[Vec2[float32]]
11 color22: VertexAttribute[Vec3[float32]]
3 12
4 when isMainModule: 13 when isMainModule:
5 var myengine = igniteEngine() 14 var myengine = igniteEngine()
15 var mymesh1 = new Mesh[VertexDataA]
16 mymesh1.vertexData = VertexDataA(
17 position11: VertexAttribute[Vec2[float32]](
18 data: @[
19 Vec2([-0.5'f32, -0.5'f32]),
20 Vec2([ 0.5'f32, 0.5'f32]),
21 Vec2([-0.5'f32, 0.5'f32]),
22 ]
23 ),
24 color22: VertexAttribute[Vec3[float32]](
25 data: @[
26 Vec3([1.0'f32, 1.0'f32, 0.0'f32]),
27 Vec3([0.0'f32, 1.0'f32, 0.0'f32]),
28 Vec3([0.0'f32, 1.0'f32, 1.0'f32]),
29 ]
30 )
31 )
32 var mymesh2 = new IndexedMesh[VertexDataA, uint16]
33 mymesh2.vertexData = VertexDataA(
34 position11: VertexAttribute[Vec2[float32]](
35 data: @[
36 Vec2([ 0.0'f32, -0.7'f32]),
37 Vec2([ 0.6'f32, 0.1'f32]),
38 Vec2([ 0.3'f32, 0.4'f32]),
39 ]
40 ),
41 color22: VertexAttribute[Vec3[float32]](
42 data: @[
43 Vec3([1.0'f32, 1.0'f32, 0.0'f32]),
44 Vec3([1.0'f32, 0.0'f32, 0.0'f32]),
45 Vec3([0.0'f32, 1.0'f32, 1.0'f32]),
46 ]
47 )
48 )
49 mymesh2.indices = @[[0'u16, 1'u16, 2'u16]]
50 var athing = new Thing
51 athing.parts.add mymesh1
52 var childthing = new Thing
53 childthing.parts.add mymesh2
54 athing.children.add childthing
55
56 setupPipeline[VertexDataA, uint16](
57 myengine,
58 athing,
59 generateVertexShaderCode[VertexDataA]("main", "position11", "color22"),
60 generateFragmentShaderCode[VertexDataA]("main"),
61 )
6 myengine.fullThrottle() 62 myengine.fullThrottle()
7 myengine.trash() 63 myengine.trash()