comparison examples/E01_hello_triangle.nim @ 796:8084252b807a

fix: first example
author Sam <sam@basx.dev>
date Mon, 04 Sep 2023 00:55:35 +0700
parents 754835bf175e
children 812b5e28f441
comparison
equal deleted inserted replaced
795:4a15d94d9418 796:8084252b807a
1 import std/tables
2
1 import ../src/semicongine 3 import ../src/semicongine
2 4
3 5 # shader setup
4 const 6 const
5 inputs = @[ 7 shaderConfiguration = createShaderConfiguration(
6 attr[Vec3f]("position"), 8 inputs=[
7 attr[Vec4f]("color"), 9 attr[Vec3f]("position"),
8 ] 10 attr[Vec4f]("color"),
9 intermediate = @[attr[Vec4f]("outcolor")] 11 ],
10 outputs = @[attr[Vec4f]("color")] 12 intermediates=[attr[Vec4f]("outcolor")],
11 (vertexCode, fragmentCode) = compileVertexFragmentShaderSet( 13 outputs=[attr[Vec4f]("color")],
12 inputs=inputs, 14 vertexCode="gl_Position = vec4(position, 1.0); outcolor = color;",
13 intermediate=intermediate,
14 outputs=outputs,
15 vertexCode="""
16 gl_Position = vec4(position, 1.0);
17 outcolor = color;
18 """,
19 fragmentCode="color = outcolor;", 15 fragmentCode="color = outcolor;",
20 ) 16 )
21 17
18 # scene setup
22 var 19 var
23 triangle = newScene("scene", newEntity( 20 triangle = Scene(name: "scene",
24 "triangle", 21 meshes: @[newMesh(
25 {"mesh": Component(newMesh(
26 [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], 22 [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)],
27 [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], 23 [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)],
28 ))} 24 material=Material(name: "")
29 )) 25 )]
26 )
30 myengine = initEngine("Hello triangle") 27 myengine = initEngine("Hello triangle")
31 renderPass = myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)
32 28
33 myengine.setRenderer(renderPass) 29 myengine.initRenderer({"": shaderConfiguration}.toTable)
34 myengine.addScene(triangle, inputs, @[], transformAttribute="") 30 myengine.addScene(triangle)
35 31
36 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): 32 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape):
37 myengine.renderScene(triangle) 33 myengine.renderScene(triangle)
38 34
39 myengine.destroy() 35 myengine.destroy()