annotate examples/E01_hello_triangle.nim @ 336:887ddc8d45fd

did: update examples to work with improved scenegraph/material api, notice removed complexity!
author Sam <sam@basx.dev>
date Tue, 05 Sep 2023 00:28:35 +0700
parents f05b4bef44d1
children c66503386e8b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
335
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
1 import std/tables
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
2
271
95281f2db400 did: fix API changes broke examples
Sam <sam@basx.dev>
parents: 253
diff changeset
3 import ../src/semicongine
0
5daf3f236d87 add: initial version
Sam <sam@basx.dev>
parents:
diff changeset
4
335
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
5 # shader setup
133
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
6 const
335
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
7 shaderConfiguration = createShaderConfiguration(
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
8 inputs=[
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
9 attr[Vec3f]("position"),
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
10 attr[Vec4f]("color"),
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
11 ],
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
12 intermediates=[attr[Vec4f]("outcolor")],
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
13 outputs=[attr[Vec4f]("color")],
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
14 vertexCode="gl_Position = vec4(position, 1.0); outcolor = color;",
316
b145a05c2459 add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 302
diff changeset
15 fragmentCode="color = outcolor;",
133
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
16 )
19
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents: 12
diff changeset
17
335
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
18 # scene setup
133
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
19 var
335
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
20 triangle = Scene(name: "scene",
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
21 meshes: @[newMesh(
133
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
22 [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)],
210
f3912838cd69 fix: always use rgba
Sam <sam@basx.dev>
parents: 203
diff changeset
23 [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)],
336
887ddc8d45fd did: update examples to work with improved scenegraph/material api, notice removed complexity!
Sam <sam@basx.dev>
parents: 335
diff changeset
24 material=Material(name: "default")
335
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
25 )]
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
26 )
133
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
27 myengine = initEngine("Hello triangle")
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
28
336
887ddc8d45fd did: update examples to work with improved scenegraph/material api, notice removed complexity!
Sam <sam@basx.dev>
parents: 335
diff changeset
29 myengine.initRenderer({"default": shaderConfiguration}.toTable)
335
f05b4bef44d1 fix: first example
Sam <sam@basx.dev>
parents: 316
diff changeset
30 myengine.addScene(triangle)
133
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
31
145
a4e6e76128e6 add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents: 136
diff changeset
32 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape):
133
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
33 myengine.renderScene(triangle)
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
34
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
35 myengine.destroy()