Mercurial > games > semicongine
comparison examples/E03_hello_cube.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 | d3e014c3551c |
comparison
equal
deleted
inserted
replaced
| 1139:114f395b9144 | 1140:5934c5615f13 |
|---|---|
| 38 let off = i * 4 | 38 let off = i * 4 |
| 39 tris.add [off + 0'u16, off + 1'u16, off + 2'u16] | 39 tris.add [off + 0'u16, off + 1'u16, off + 2'u16] |
| 40 tris.add [off + 2'u16, off + 3'u16, off + 0'u16] | 40 tris.add [off + 2'u16, off + 3'u16, off + 0'u16] |
| 41 | 41 |
| 42 when isMainModule: | 42 when isMainModule: |
| 43 var myengine = initEngine("Hello cube") | 43 var myengine = InitEngine("Hello cube") |
| 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 ], | 51 ], |
| 52 intermediates = [attr[Vec4f]("outcolor")], | 52 intermediates = [Attr[Vec4f]("outcolor")], |
| 53 uniforms = [ | 53 uniforms = [ |
| 54 attr[Mat4]("projection"), | 54 Attr[Mat4]("projection"), |
| 55 attr[Mat4]("view"), | 55 Attr[Mat4]("view"), |
| 56 attr[Mat4]("model"), | 56 Attr[Mat4]("model"), |
| 57 ], | 57 ], |
| 58 outputs = [attr[Vec4f]("color")], | 58 outputs = [Attr[Vec4f]("color")], |
| 59 vertexCode = """outcolor = color; gl_Position = (Uniforms.projection * Uniforms.view * Uniforms.model) * vec4(position, 1);""", | 59 vertexCode = """outcolor = color; gl_Position = (Uniforms.projection * Uniforms.view * Uniforms.model) * vec4(position, 1);""", |
| 60 fragmentCode = "color = outcolor;", | 60 fragmentCode = "color = outcolor;", |
| 61 ) | 61 ) |
| 62 var matDef = MaterialType(name: "default material", vertexAttributes: {"position": Vec3F32, "color": Vec4F32}.toTable) | 62 var matDef = MaterialType(name: "default material", vertexAttributes: {"position": Vec3F32, "color": Vec4F32}.toTable) |
| 63 var cube = Scene(name: "scene", meshes: @[newMesh(positions = cube_pos, indices = tris, colors = cube_color, material = matDef.InitMaterialData(name = "default"))]) | 63 var cube = Scene(name: "scene", meshes: @[NewMesh(positions = cube_pos, indices = tris, colors = cube_color, material = matDef.InitMaterialData(name = "default"))]) |
| 64 cube.addShaderGlobal("projection", Unit4f32) | 64 cube.AddShaderGlobal("projection", Unit4f32) |
| 65 cube.addShaderGlobal("view", Unit4f32) | 65 cube.AddShaderGlobal("view", Unit4f32) |
| 66 cube.addShaderGlobal("model", Unit4f32) | 66 cube.AddShaderGlobal("model", Unit4f32) |
| 67 myengine.initRenderer({matDef: shaderConfiguration}) | 67 myengine.InitRenderer({matDef: shaderConfiguration}) |
| 68 myengine.loadScene(cube) | 68 myengine.LoadScene(cube) |
| 69 | 69 |
| 70 var t: float32 = cpuTime() | 70 var t: float32 = cpuTime() |
| 71 while myengine.UpdateInputs() and not KeyWasPressed(Escape): | 71 while myengine.UpdateInputs() and not KeyWasPressed(Escape): |
| 72 setShaderGlobal(cube, "model", translate(0'f32, 0'f32, 10'f32) * rotate(t, Yf32)) | 72 SetShaderGlobal(cube, "model", Translate(0'f32, 0'f32, 10'f32) * Rotate(t, Yf32)) |
| 73 setShaderGlobal(cube, "projection", | 73 SetShaderGlobal(cube, "projection", |
| 74 perspective( | 74 Perspective( |
| 75 float32(PI / 4), | 75 float32(PI / 4), |
| 76 float32(myengine.GetWindow().size[0]) / float32(myengine.GetWindow().size[1]), | 76 float32(myengine.GetWindow().Size[0]) / float32(myengine.GetWindow().Size[1]), |
| 77 0.1'f32, | 77 0.1'f32, |
| 78 100'f32 | 78 100'f32 |
| 79 ) | 79 ) |
| 80 ) | 80 ) |
| 81 t = cpuTime() | 81 t = cpuTime() |
| 82 myengine.renderScene(cube) | 82 myengine.RenderScene(cube) |
| 83 | 83 |
| 84 myengine.destroy() | 84 myengine.Destroy() |
