diff options
Diffstat (limited to 'bin/game/main.lua')
-rw-r--r-- | bin/game/main.lua | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/bin/game/main.lua b/bin/game/main.lua index ce5b62c..3ce17a0 100644 --- a/bin/game/main.lua +++ b/bin/game/main.lua @@ -20,7 +20,11 @@ end local particle_sprites = {} local Pi = 3.1415 local sinShader = nil +local screen = nil +local pp = nil +local pixel = nil function jin.core.onLoad() + screen = jin.graphics.newCanvas(jin.graphics.getSize()) -- bitmap = jin.graphics.newBitmap(200, 200, function(w, h, x, y) -- return {255*math.sin(x/w),255 - 255,255*math.cos(y/w),255} -- end) @@ -103,6 +107,54 @@ function jin.core.onLoad() } #END_FRAGMENT_SHADER ]] + + pp = jin.graphics.newShader[[ + #VERTEX_SHADER + Vertex vert(Vertex v) + { + return v; + } + #END_VERTEX_SHADER + #FRAGMENT_SHADER + Color frag(Color col, Texture tex, Vertex v) + { + v.uv.x += sin(v.uv.y * 4 * 2 * 3.14 + jin_Time.x) / (10 + sin(jin_Time.x) * 10); + return texel(tex, v.uv); + } + #END_FRAGMENT_SHADER + ]] + + pixel = jin.graphics.newShader[[ + #VERTEX_SHADER + Vertex vert(Vertex v) + { + return v; + } + #END_VERTEX_SHADER + #FRAGMENT_SHADER + Color frag(Color col, Texture tex, Vertex v) + { + // config + float pixel_w = 10.0; + float pixel_h = 10.0; + + vec2 uv = v.uv; + vec3 tc = vec3(1.0, 0.0, 0.0); + if(uv.x < abs(sin(jin_Time.x))) + { + float dx = pixel_w*(1.0/jin_RenderTargetSize.x); + float dy = pixel_h*(1.0/jin_RenderTargetSize.y); + vec2 coord = vec2(dx*floor(uv.x/dx),dy*floor(uv.y/dy)); + tc = texel(tex, coord).rgb; + } + else + { + tc = texel(tex, uv).rgb; + } + return vec4(tc, 1.0); + } + #END_FRAGMENT_SHADER + ]] jin.log.info("test") @@ -127,6 +179,11 @@ function jin.core.onEvent(e) if e.type == "Quit" then jin.core.stop() end + if e.type == "MouseButtonDown" then + if e.button == "Left" then + ps:setPosition(e.x, e.y) + end + end end local t = 0 @@ -142,6 +199,8 @@ function jin.core.onUpdate(dt) end function jin.core.onDraw() + jin.graphics.bindCanvas(screen) + jin.graphics.clear() jin.graphics.useShader(jin.graphics.Shaders.Shape) jin.graphics.setColor(255, 0, 255, 255) jin.graphics.rect(jin.graphics.RenderMode.FILL, 30, 50, 100, 200) @@ -166,4 +225,9 @@ function jin.core.onDraw() jin.graphics.unuseShader() jin.graphics.setColor(255, 255, 255, 255) jin.graphics.print(jin.graphics.getStatsStr(), 450, 10) + + jin.graphics.unbindCanvas(screen) + jin.graphics.useShader(pixel) + jin.graphics.draw(screen, 0, 0) + jin.graphics.unuseShader() end
\ No newline at end of file |