diff examples/E01_hello_triangle.nim @ 1059:9c364af8d3f0

did: tons of small improvments, on the way to make GPU sync (more) correct I guess
author sam <sam@basx.dev>
date Sun, 31 Mar 2024 22:11:50 +0700
parents c66503386e8b
children 4692be6e07eb 79c0f3271748
line wrap: on
line diff
--- a/examples/E01_hello_triangle.nim	Sun Mar 31 18:13:46 2024 +0700
+++ b/examples/E01_hello_triangle.nim	Sun Mar 31 22:11:50 2024 +0700
@@ -1,35 +1,37 @@
 import std/tables
 
-import ../src/semicongine
+import ../semicongine
 
 # shader setup
 const
   shaderConfiguration = createShaderConfiguration(
-    inputs=[
+    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;",
+    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",
+  scene = 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")
+      positions = [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)],
+      colors = [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)],
+      material = VERTEX_COLORED_MATERIAL.initMaterialData()
     )]
   )
-  myengine = initEngine("Hello triangle")
+  myengine = initEngine("Hello triangle", showFps = true)
 
-myengine.initRenderer({"default": shaderConfiguration}.toTable)
-myengine.addScene(triangle)
+myengine.initRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}, vSync = false, inFlightFrames = 1)
+myengine.loadScene(scene)
 
 while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape):
-  myengine.renderScene(triangle)
+  echo ""
+  transform[Vec3f](scene.meshes[0][], "position", scale(1.001, 1.001))
+  myengine.renderScene(scene)
 
 myengine.destroy()