Mercurial > games > semicongine
comparison examples/E01_hello_triangle.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 |
---|---|
2 | 2 |
3 import ../semicongine | 3 import ../semicongine |
4 | 4 |
5 # shader setup | 5 # shader setup |
6 const | 6 const |
7 shaderConfiguration = createShaderConfiguration( | 7 shaderConfiguration = CreateShaderConfiguration( |
8 name = "default shader", | 8 name = "default shader", |
9 inputs = [ | 9 inputs = [ |
10 attr[Vec3f]("position"), | 10 Attr[Vec3f]("position"), |
11 attr[Vec4f]("color"), | 11 Attr[Vec4f]("color"), |
12 ], | 12 ], |
13 intermediates = [attr[Vec4f]("outcolor")], | 13 intermediates = [Attr[Vec4f]("outcolor")], |
14 outputs = [attr[Vec4f]("color")], | 14 outputs = [Attr[Vec4f]("color")], |
15 vertexCode = "gl_Position = vec4(position, 1.0); outcolor = color;", | 15 vertexCode = "gl_Position = vec4(position, 1.0); outcolor = color;", |
16 fragmentCode = "color = outcolor;", | 16 fragmentCode = "color = outcolor;", |
17 ) | 17 ) |
18 | 18 |
19 # scene setup | 19 # scene setup |
20 var | 20 var |
21 scene = Scene(name: "scene", | 21 scene = Scene(name: "scene", |
22 meshes: @[newMesh( | 22 meshes: @[NewMesh( |
23 positions = [NewVec3f(-0.5, 0.5), NewVec3f(0, -0.5), NewVec3f(0.5, 0.5)], | 23 positions = [NewVec3f(-0.5, 0.5), NewVec3f(0, -0.5), NewVec3f(0.5, 0.5)], |
24 colors = [NewVec4f(1, 0, 0, 1), NewVec4f(0, 1, 0, 1), NewVec4f(0, 0, 1, 1)], | 24 colors = [NewVec4f(1, 0, 0, 1), NewVec4f(0, 1, 0, 1), NewVec4f(0, 0, 1, 1)], |
25 material = VERTEX_COLORED_MATERIAL.InitMaterialData() | 25 material = VERTEX_COLORED_MATERIAL.InitMaterialData() |
26 )] | 26 )] |
27 ) | 27 ) |
28 myengine = initEngine("Hello triangle", showFps = true) | 28 myengine = InitEngine("Hello triangle", showFps = true) |
29 | 29 |
30 myengine.initRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}, inFlightFrames = 2) | 30 myengine.InitRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}, inFlightFrames = 2) |
31 myengine.loadScene(scene) | 31 myengine.LoadScene(scene) |
32 | 32 |
33 while myengine.UpdateInputs() and not KeyWasPressed(Escape): | 33 while myengine.UpdateInputs() and not KeyWasPressed(Escape): |
34 transform[Vec3f](scene.meshes[0][], "position", scale(1.001, 1.001)) | 34 Transform[Vec3f](scene.meshes[0][], "position", Scale(1.001, 1.001)) |
35 myengine.renderScene(scene) | 35 myengine.RenderScene(scene) |
36 | 36 |
37 myengine.destroy() | 37 myengine.Destroy() |