view examples/E01_hello_triangle.nim @ 342:8c67f67b62fb

fix: attributes with same name but different gpu memory lead to wrong results
author Sam <sam@basx.dev>
date Mon, 11 Sep 2023 18:23:15 +0700
parents 887ddc8d45fd
children c66503386e8b
line wrap: on
line source

import std/tables

import ../src/semicongine

# shader setup
const
  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 = 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: "default")
    )]
  )
  myengine = initEngine("Hello triangle")

myengine.initRenderer({"default": shaderConfiguration}.toTable)
myengine.addScene(triangle)

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

myengine.destroy()