Mercurial > games > semicongine
annotate examples/E01_hello_triangle.nim @ 333:27aaf43e18b4
fix: material handling, gltf loading, loader example
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 04 Sep 2023 00:31:17 +0700 |
parents | b145a05c2459 |
children | f05b4bef44d1 |
rev | line source |
---|---|
271 | 1 import ../src/semicongine |
0 | 2 |
3 | |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
4 const |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
5 inputs = @[ |
163 | 6 attr[Vec3f]("position"), |
210 | 7 attr[Vec4f]("color"), |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
8 ] |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
9 intermediate = @[attr[Vec4f]("outcolor")] |
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
10 outputs = @[attr[Vec4f]("color")] |
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
11 (vertexCode, fragmentCode) = compileVertexFragmentShaderSet( |
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
12 inputs=inputs, |
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
13 intermediate=intermediate, |
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
14 outputs=outputs, |
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
15 vertexCode=""" |
136
fc5db4f1f94e
did: rewrite example 02 with new engine approach
Sam <sam@basx.dev>
parents:
133
diff
changeset
|
16 gl_Position = vec4(position, 1.0); |
fc5db4f1f94e
did: rewrite example 02 with new engine approach
Sam <sam@basx.dev>
parents:
133
diff
changeset
|
17 outcolor = color; |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
18 """, |
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
19 fragmentCode="color = outcolor;", |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
20 ) |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
12
diff
changeset
|
21 |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
22 var |
203
84fd522fdf3f
did: update examples to use new API for scene + scene globals
Sam <sam@basx.dev>
parents:
163
diff
changeset
|
23 triangle = newScene("scene", newEntity( |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
24 "triangle", |
302 | 25 {"mesh": Component(newMesh( |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
26 [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], |
210 | 27 [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], |
302 | 28 ))} |
203
84fd522fdf3f
did: update examples to use new API for scene + scene globals
Sam <sam@basx.dev>
parents:
163
diff
changeset
|
29 )) |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
30 myengine = initEngine("Hello triangle") |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
31 renderPass = myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode) |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
32 |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
33 myengine.setRenderer(renderPass) |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
302
diff
changeset
|
34 myengine.addScene(triangle, inputs, @[], transformAttribute="") |
133
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
35 |
145
a4e6e76128e6
add: upgrade all simple examples to new engine version
Sam <sam@basx.dev>
parents:
136
diff
changeset
|
36 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
|
37 myengine.renderScene(triangle) |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
38 |
9f2c178beb60
add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents:
74
diff
changeset
|
39 myengine.destroy() |