Mercurial > games > semicongine
changeset 796:8084252b807a
fix: first example
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 04 Sep 2023 00:55:35 +0700 |
parents | 4a15d94d9418 |
children | 812b5e28f441 |
files | examples/E01_hello_triangle.nim |
diffstat | 1 files changed, 19 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/E01_hello_triangle.nim Mon Sep 04 00:48:00 2023 +0700 +++ b/examples/E01_hello_triangle.nim Mon Sep 04 00:55:35 2023 +0700 @@ -1,37 +1,33 @@ +import std/tables + import ../src/semicongine - +# shader setup const - inputs = @[ - attr[Vec3f]("position"), - attr[Vec4f]("color"), - ] - intermediate = @[attr[Vec4f]("outcolor")] - outputs = @[attr[Vec4f]("color")] - (vertexCode, fragmentCode) = compileVertexFragmentShaderSet( - inputs=inputs, - intermediate=intermediate, - outputs=outputs, - vertexCode=""" - gl_Position = vec4(position, 1.0); - outcolor = color; - """, + shaderConfiguration = createShaderConfiguration( + inputs=[ + attr[Vec3f]("position"), + attr[Vec4f]("color"), + ], + intermediates=[attr[Vec4f]("outcolor")], + outputs=[attr[Vec4f]("color")], + vertexCode="gl_Position = vec4(position, 1.0); outcolor = color;", fragmentCode="color = outcolor;", ) +# scene setup var - triangle = newScene("scene", newEntity( - "triangle", - {"mesh": Component(newMesh( + triangle = Scene(name: "scene", + meshes: @[newMesh( [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], - ))} - )) + material=Material(name: "") + )] + ) myengine = initEngine("Hello triangle") - renderPass = myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode) -myengine.setRenderer(renderPass) -myengine.addScene(triangle, inputs, @[], transformAttribute="") +myengine.initRenderer({"": shaderConfiguration}.toTable) +myengine.addScene(triangle) while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): myengine.renderScene(triangle)