view examples/E01_hello_triangle.nim @ 304:0c6e73fcc61f

Merge branch 'main' of github.com:saemideluxe/semicongine
author Sam <sam@basx.dev>
date Tue, 27 Jun 2023 00:17:55 +0700
parents da0bd61abe91
children b145a05c2459
line wrap: on
line source

import ../src/semicongine


const
  vertexInput = @[
    attr[Vec3f]("position"),
    attr[Vec4f]("color"),
  ]
  vertexOutput = @[attr[Vec4f]("outcolor")]
  fragOutput = @[attr[Vec4f]("color")]
  vertexCode = compileGlslShader(
    stage=VK_SHADER_STAGE_VERTEX_BIT,
    inputs=vertexInput,
    outputs=vertexOutput,
    main="""
    gl_Position = vec4(position, 1.0);
    outcolor = color;
    """
  )
  fragmentCode = compileGlslShader(
    stage=VK_SHADER_STAGE_FRAGMENT_BIT,
    inputs=vertexOutput,
    outputs=fragOutput,
    main="color = outcolor;"
  )

var
  triangle = newScene("scene", newEntity(
    "triangle",
    {"mesh": Component(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)],
    ))}
  ))
  myengine = initEngine("Hello triangle")
  renderPass = myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)

myengine.setRenderer(renderPass)
myengine.addScene(triangle, vertexInput, @[], transformAttribute="")

while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape):
  myengine.renderScene(triangle)

myengine.destroy()