Mercurial > games > semicongine
comparison examples/E01_hello_triangle.nim @ 950:fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
author | sam <sam@basx.dev> |
---|---|
date | Sun, 31 Mar 2024 22:11:50 +0700 |
parents | c66503386e8b |
children | 4692be6e07eb 79c0f3271748 |
comparison
equal
deleted
inserted
replaced
949:0cf68e7336e8 | 950:fe48b091e83f |
---|---|
1 import std/tables | 1 import std/tables |
2 | 2 |
3 import ../src/semicongine | 3 import ../semicongine |
4 | 4 |
5 # shader setup | 5 # shader setup |
6 const | 6 const |
7 shaderConfiguration = createShaderConfiguration( | 7 shaderConfiguration = createShaderConfiguration( |
8 inputs=[ | 8 inputs = [ |
9 attr[Vec3f]("position"), | 9 attr[Vec3f]("position"), |
10 attr[Vec4f]("color"), | 10 attr[Vec4f]("color"), |
11 ], | 11 ], |
12 intermediates=[attr[Vec4f]("outcolor")], | 12 intermediates = [attr[Vec4f]("outcolor")], |
13 outputs=[attr[Vec4f]("color")], | 13 outputs = [attr[Vec4f]("color")], |
14 vertexCode="gl_Position = vec4(position, 1.0); outcolor = color;", | 14 vertexCode = "gl_Position = vec4(position, 1.0); outcolor = color;", |
15 fragmentCode="color = outcolor;", | 15 fragmentCode = "color = outcolor;", |
16 ) | 16 ) |
17 | 17 |
18 # scene setup | 18 # scene setup |
19 var | 19 var |
20 triangle = Scene(name: "scene", | 20 scene = Scene(name: "scene", |
21 meshes: @[newMesh( | 21 meshes: @[newMesh( |
22 [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], | 22 positions = [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], |
23 [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], | 23 colors = [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], |
24 material=Material(name: "default") | 24 material = VERTEX_COLORED_MATERIAL.initMaterialData() |
25 )] | 25 )] |
26 ) | 26 ) |
27 myengine = initEngine("Hello triangle") | 27 myengine = initEngine("Hello triangle", showFps = true) |
28 | 28 |
29 myengine.initRenderer({"default": shaderConfiguration}.toTable) | 29 myengine.initRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}, vSync = false, inFlightFrames = 1) |
30 myengine.addScene(triangle) | 30 myengine.loadScene(scene) |
31 | 31 |
32 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): | 32 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): |
33 myengine.renderScene(triangle) | 33 echo "" |
34 transform[Vec3f](scene.meshes[0][], "position", scale(1.001, 1.001)) | |
35 myengine.renderScene(scene) | |
34 | 36 |
35 myengine.destroy() | 37 myengine.destroy() |