comparison examples/E10_pong.nim @ 210:f3912838cd69

fix: always use rgba
author Sam <sam@basx.dev>
date Tue, 09 May 2023 18:19:17 +0700
parents 84fd522fdf3f
children 952428f04ffc
comparison
equal deleted inserted replaced
209:461c18ee759b 210:f3912838cd69
1 import std/times 1 import std/times
2 2
3 import semicongine 3 import semicongine
4 4
5 let 5 let
6 barcolor = hexToColor("5A3F00").gamma(2.2).colorToHex() 6 barcolor = hexToColorAlpha("5A3F00").gamma(2.2).colorToHex()
7 barSize = 0.1'f 7 barSize = 0.1'f
8 barWidth = 0.01'f 8 barWidth = 0.01'f
9 ballcolor = hexToColor("B17F08").gamma(2.2).colorToHex() 9 ballcolor = hexToColorAlpha("B17F08").gamma(2.2).colorToHex()
10 ballSize = 0.01'f 10 ballSize = 0.01'f
11 backgroundColor = hexToColorAlpha("FAC034FF").gamma(2.2) 11 backgroundColor = hexToColorAlpha("FAC034FF").gamma(2.2)
12 ballSpeed = 60'f 12 ballSpeed = 60'f
13 13
14 var 14 var
31 level.root.add ball 31 level.root.add ball
32 32
33 const 33 const
34 vertexInput = @[ 34 vertexInput = @[
35 attr[Vec3f]("position"), 35 attr[Vec3f]("position"),
36 attr[Vec3f]("color", memoryPerformanceHint=PreferFastWrite), 36 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite),
37 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), 37 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true),
38 ] 38 ]
39 vertexOutput = @[attr[Vec3f]("outcolor")] 39 vertexOutput = @[attr[Vec4f]("outcolor")]
40 uniforms = @[attr[Mat4]("projection")] 40 uniforms = @[attr[Mat4]("projection")]
41 fragOutput = @[attr[Vec4f]("color")] 41 fragOutput = @[attr[Vec4f]("color")]
42 vertexCode = compileGlslShader( 42 vertexCode = compileGlslShader(
43 stage=VK_SHADER_STAGE_VERTEX_BIT, 43 stage=VK_SHADER_STAGE_VERTEX_BIT,
44 inputs=vertexInput, 44 inputs=vertexInput,
49 fragmentCode = compileGlslShader( 49 fragmentCode = compileGlslShader(
50 stage=VK_SHADER_STAGE_FRAGMENT_BIT, 50 stage=VK_SHADER_STAGE_FRAGMENT_BIT,
51 inputs=vertexOutput, 51 inputs=vertexOutput,
52 uniforms=uniforms, 52 uniforms=uniforms,
53 outputs=fragOutput, 53 outputs=fragOutput,
54 main="color = vec4(outcolor, 1);" 54 main="color = outcolor;"
55 ) 55 )
56 56
57 # set up rendering 57 # set up rendering
58 myengine.setRenderer(myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=backgroundColor)) 58 myengine.setRenderer(myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=backgroundColor))
59 myengine.addScene(level, vertexInput, transformAttribute="transform") 59 myengine.addScene(level, vertexInput, transformAttribute="transform")