Mercurial > games > semicongine
comparison tests/test_mesh.nim @ 222:ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 15 May 2023 00:34:00 +0700 |
parents | |
children | 027f6ff06585 |
comparison
equal
deleted
inserted
replaced
221:2a2367d289dd | 222:ddfc54036e00 |
---|---|
1 import std/times | |
2 | |
3 import semicongine | |
4 | |
5 proc main() = | |
6 var scene = loadScene("test1.glb") | |
7 # var scene = loadScene("tutorialk-donat.glb") | |
8 | |
9 var engine = initEngine("Test meshes") | |
10 const | |
11 vertexInput = @[attr[Vec3f]("POSITION", memoryPerformanceHint=PreferFastRead)] | |
12 fragOutput = @[attr[Vec4f]("color")] | |
13 uniforms = @[attr[Mat4]("transform")] | |
14 vertexCode = compileGlslShader( | |
15 stage=VK_SHADER_STAGE_VERTEX_BIT, | |
16 inputs=vertexInput, | |
17 uniforms=uniforms, | |
18 main="""gl_Position = vec4(POSITION * 0.2, 1.0) * Uniforms.transform;""" | |
19 ) | |
20 fragmentCode = compileGlslShader( | |
21 stage=VK_SHADER_STAGE_FRAGMENT_BIT, | |
22 outputs=fragOutput, | |
23 uniforms=uniforms, | |
24 main=""" | |
25 color = vec4(61/255, 43/255, 31/255, 1); | |
26 """ | |
27 ) | |
28 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)) | |
29 engine.addScene(scene, vertexInput) | |
30 let rotateAxis = newVec3f(1, 1, 1) | |
31 scene.addShaderGlobal("transform", rotate3d(0'f32, rotateAxis)) | |
32 var t = cpuTime() | |
33 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): | |
34 scene.setShaderGlobal("transform", rotate3d(float32(cpuTime() - t), rotateAxis)) | |
35 engine.renderScene(scene) | |
36 engine.destroy() | |
37 | |
38 | |
39 when isMainModule: | |
40 main() |