Mercurial > games > semicongine
diff 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 |
line wrap: on
line diff
--- a/examples/E03_hello_cube.nim Sat Jun 08 14:58:25 2024 +0700 +++ b/examples/E03_hello_cube.nim Sat Jun 08 15:16:17 2024 +0700 @@ -40,45 +40,45 @@ tris.add [off + 2'u16, off + 3'u16, off + 0'u16] when isMainModule: - var myengine = initEngine("Hello cube") + var myengine = InitEngine("Hello cube") const - shaderConfiguration = createShaderConfiguration( + shaderConfiguration = CreateShaderConfiguration( name = "default shader", inputs = [ - attr[Vec3f]("position"), - attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), + Attr[Vec3f]("position"), + Attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), ], - intermediates = [attr[Vec4f]("outcolor")], + intermediates = [Attr[Vec4f]("outcolor")], uniforms = [ - attr[Mat4]("projection"), - attr[Mat4]("view"), - attr[Mat4]("model"), + Attr[Mat4]("projection"), + Attr[Mat4]("view"), + Attr[Mat4]("model"), ], - outputs = [attr[Vec4f]("color")], + outputs = [Attr[Vec4f]("color")], vertexCode = """outcolor = color; gl_Position = (Uniforms.projection * Uniforms.view * Uniforms.model) * vec4(position, 1);""", fragmentCode = "color = outcolor;", ) var matDef = MaterialType(name: "default material", vertexAttributes: {"position": Vec3F32, "color": Vec4F32}.toTable) - var cube = Scene(name: "scene", meshes: @[newMesh(positions = cube_pos, indices = tris, colors = cube_color, material = matDef.InitMaterialData(name = "default"))]) - cube.addShaderGlobal("projection", Unit4f32) - cube.addShaderGlobal("view", Unit4f32) - cube.addShaderGlobal("model", Unit4f32) - myengine.initRenderer({matDef: shaderConfiguration}) - myengine.loadScene(cube) + var cube = Scene(name: "scene", meshes: @[NewMesh(positions = cube_pos, indices = tris, colors = cube_color, material = matDef.InitMaterialData(name = "default"))]) + cube.AddShaderGlobal("projection", Unit4f32) + cube.AddShaderGlobal("view", Unit4f32) + cube.AddShaderGlobal("model", Unit4f32) + myengine.InitRenderer({matDef: shaderConfiguration}) + myengine.LoadScene(cube) var t: float32 = cpuTime() while myengine.UpdateInputs() and not KeyWasPressed(Escape): - setShaderGlobal(cube, "model", translate(0'f32, 0'f32, 10'f32) * rotate(t, Yf32)) - setShaderGlobal(cube, "projection", - perspective( + SetShaderGlobal(cube, "model", Translate(0'f32, 0'f32, 10'f32) * Rotate(t, Yf32)) + SetShaderGlobal(cube, "projection", + Perspective( float32(PI / 4), - float32(myengine.GetWindow().size[0]) / float32(myengine.GetWindow().size[1]), + float32(myengine.GetWindow().Size[0]) / float32(myengine.GetWindow().Size[1]), 0.1'f32, 100'f32 ) ) t = cpuTime() - myengine.renderScene(cube) + myengine.RenderScene(cube) - myengine.destroy() + myengine.Destroy()