Mercurial > games > semicongine
comparison examples/E02_squares.nim @ 1140:5934c5615f13
did: update all examples to work with latest refactoring
author | sam <sam@basx.dev> |
---|---|
date | Sat, 08 Jun 2024 15:16:17 +0700 |
parents | 114f395b9144 |
children |
comparison
equal
deleted
inserted
replaced
1139:114f395b9144 | 1140:5934c5615f13 |
---|---|
41 indices[squareIndex * 2 + 0] = [uint16(vertIndex + 0), uint16(vertIndex + 1), uint16(vertIndex + 2)] | 41 indices[squareIndex * 2 + 0] = [uint16(vertIndex + 0), uint16(vertIndex + 1), uint16(vertIndex + 2)] |
42 indices[squareIndex * 2 + 1] = [uint16(vertIndex + 2), uint16(vertIndex + 3), uint16(vertIndex + 0)] | 42 indices[squareIndex * 2 + 1] = [uint16(vertIndex + 2), uint16(vertIndex + 3), uint16(vertIndex + 0)] |
43 | 43 |
44 | 44 |
45 const | 45 const |
46 shaderConfiguration = createShaderConfiguration( | 46 shaderConfiguration = CreateShaderConfiguration( |
47 name = "default shader", | 47 name = "default shader", |
48 inputs = [ | 48 inputs = [ |
49 attr[Vec3f]("position"), | 49 Attr[Vec3f]("position"), |
50 attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), | 50 Attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), |
51 attr[uint32]("index"), | 51 Attr[uint32]("index"), |
52 ], | 52 ], |
53 intermediates = [attr[Vec4f]("outcolor")], | 53 intermediates = [Attr[Vec4f]("outcolor")], |
54 uniforms = [attr[float32]("time")], | 54 uniforms = [Attr[float32]("time")], |
55 outputs = [attr[Vec4f]("color")], | 55 outputs = [Attr[Vec4f]("color")], |
56 vertexCode = """ | 56 vertexCode = """ |
57 float pos_weight = index / 100.0; // add some gamma correction? | 57 float pos_weight = index / 100.0; // add some gamma correction? |
58 float t = sin(Uniforms.time * 0.5) * 0.5 + 0.5; | 58 float t = sin(Uniforms.time * 0.5) * 0.5 + 0.5; |
59 float v = min(1, max(0, pow(pos_weight - t, 2))); | 59 float v = min(1, max(0, pow(pos_weight - t, 2))); |
60 v = pow(1 - v, 3000); | 60 v = pow(1 - v, 3000); |
66 let matDef = MaterialType(name: "default", vertexAttributes: { | 66 let matDef = MaterialType(name: "default", vertexAttributes: { |
67 "position": Vec3F32, | 67 "position": Vec3F32, |
68 "color": Vec4F32, | 68 "color": Vec4F32, |
69 "index": UInt32, | 69 "index": UInt32, |
70 }.toTable) | 70 }.toTable) |
71 var squaremesh = newMesh( | 71 var squaremesh = NewMesh( |
72 positions = vertices, | 72 positions = vertices, |
73 indices = indices, | 73 indices = indices, |
74 colors = colors, | 74 colors = colors, |
75 ) | 75 ) |
76 squaremesh[].initVertexAttribute("index", iValues.toSeq) | 76 squaremesh[].InitVertexAttribute("index", iValues.toSeq) |
77 squaremesh.material = matDef.InitMaterialData(name = "default") | 77 squaremesh.material = matDef.InitMaterialData(name = "default") |
78 | 78 |
79 var myengine = initEngine("Squares") | 79 var myengine = InitEngine("Squares") |
80 myengine.initRenderer({matDef: shaderConfiguration}) | 80 myengine.InitRenderer({matDef: shaderConfiguration}) |
81 | 81 |
82 var scene = Scene(name: "scene", meshes: @[squaremesh]) | 82 var scene = Scene(name: "scene", meshes: @[squaremesh]) |
83 scene.addShaderGlobal("time", 0.0'f32) | 83 scene.AddShaderGlobal("time", 0.0'f32) |
84 myengine.loadScene(scene) | 84 myengine.LoadScene(scene) |
85 while myengine.UpdateInputs() and not KeyWasPressed(Escape): | 85 while myengine.UpdateInputs() and not KeyWasPressed(Escape): |
86 scene.setShaderGlobal("time", getShaderGlobal[float32](scene, "time") + 0.0005'f) | 86 scene.SetShaderGlobal("time", GetShaderGlobal[float32](scene, "time") + 0.0005'f) |
87 myengine.renderScene(scene) | 87 myengine.RenderScene(scene) |
88 | 88 |
89 myengine.destroy() | 89 myengine.Destroy() |