Mercurial > games > semicongine
comparison examples/E01_hello_triangle.nim @ 316:b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 07 Aug 2023 00:23:00 +0700 |
parents | da0bd61abe91 |
children | f05b4bef44d1 |
comparison
equal
deleted
inserted
replaced
315:4921ec86dcb4 | 316:b145a05c2459 |
---|---|
1 import ../src/semicongine | 1 import ../src/semicongine |
2 | 2 |
3 | 3 |
4 const | 4 const |
5 vertexInput = @[ | 5 inputs = @[ |
6 attr[Vec3f]("position"), | 6 attr[Vec3f]("position"), |
7 attr[Vec4f]("color"), | 7 attr[Vec4f]("color"), |
8 ] | 8 ] |
9 vertexOutput = @[attr[Vec4f]("outcolor")] | 9 intermediate = @[attr[Vec4f]("outcolor")] |
10 fragOutput = @[attr[Vec4f]("color")] | 10 outputs = @[attr[Vec4f]("color")] |
11 vertexCode = compileGlslShader( | 11 (vertexCode, fragmentCode) = compileVertexFragmentShaderSet( |
12 stage=VK_SHADER_STAGE_VERTEX_BIT, | 12 inputs=inputs, |
13 inputs=vertexInput, | 13 intermediate=intermediate, |
14 outputs=vertexOutput, | 14 outputs=outputs, |
15 main=""" | 15 vertexCode=""" |
16 gl_Position = vec4(position, 1.0); | 16 gl_Position = vec4(position, 1.0); |
17 outcolor = color; | 17 outcolor = color; |
18 """ | 18 """, |
19 ) | 19 fragmentCode="color = outcolor;", |
20 fragmentCode = compileGlslShader( | |
21 stage=VK_SHADER_STAGE_FRAGMENT_BIT, | |
22 inputs=vertexOutput, | |
23 outputs=fragOutput, | |
24 main="color = outcolor;" | |
25 ) | 20 ) |
26 | 21 |
27 var | 22 var |
28 triangle = newScene("scene", newEntity( | 23 triangle = newScene("scene", newEntity( |
29 "triangle", | 24 "triangle", |
34 )) | 29 )) |
35 myengine = initEngine("Hello triangle") | 30 myengine = initEngine("Hello triangle") |
36 renderPass = myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode) | 31 renderPass = myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode) |
37 | 32 |
38 myengine.setRenderer(renderPass) | 33 myengine.setRenderer(renderPass) |
39 myengine.addScene(triangle, vertexInput, @[], transformAttribute="") | 34 myengine.addScene(triangle, inputs, @[], transformAttribute="") |
40 | 35 |
41 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): | 36 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): |
42 myengine.renderScene(triangle) | 37 myengine.renderScene(triangle) |
43 | 38 |
44 myengine.destroy() | 39 myengine.destroy() |