From 85d4fbbba7490bc409b96f2439d238b0b62aceb5 Mon Sep 17 00:00:00 2001 From: leokaplan Date: Wed, 3 Feb 2016 15:45:22 +0100 Subject: [PATCH 1/4] initial port --- conf.lua | 4 ++-- examples/complex.lua | 2 +- lib/body.lua | 7 ++++--- lib/init.lua | 37 ++++++++++++++++++++++++------------- lib/postshader.lua | 2 +- lib/util.lua | 16 ++++++++++++---- main.lua | 13 ++++++------- 7 files changed, 50 insertions(+), 31 deletions(-) diff --git a/conf.lua b/conf.lua index 91544ec..cd080d0 100644 --- a/conf.lua +++ b/conf.lua @@ -1,6 +1,6 @@ function love.conf(t) t.identity = nil -- The name of the save directory (string) - t.version = "0.9.0" -- The LÖVE version this game was made for (string) + t.version = "0.10.0" -- The LÖVE version this game was made for (string) t.console = true -- Attach a console (boolean, Windows only) t.window.title = "Untitled" -- The window title (string) @@ -12,7 +12,7 @@ function love.conf(t) t.window.minwidth = 1 -- Minimum window width if the window is resizable (number) t.window.minheight = 1 -- Minimum window height if the window is resizable (number) t.window.fullscreen = false -- Enable fullscreen (boolean) - t.window.fullscreentype = "normal" -- Standard fullscreen or desktop fullscreen mode (string) + t.window.fullscreentype = "desktop" -- Standard fullscreen or desktop fullscreen mode (string) t.window.vsync = false -- Enable vertical sync (boolean) t.window.fsaa = 0 -- The number of samples to use with multi-sampled antialiasing (number) t.window.display = 1 -- Index of the monitor to show the window in (number) diff --git a/examples/complex.lua b/examples/complex.lua index 21a9a26..c0566c4 100644 --- a/examples/complex.lua +++ b/examples/complex.lua @@ -40,7 +40,7 @@ function love.load() love.graphics.setFont(font) -- set background - quadScreen = love.graphics.newQuad(0, 0, love.window.getWidth() + 32, love.window.getHeight() + 24, 32, 24) + quadScreen = love.graphics.newQuad(0, 0, love.graphics.getWidth() + 32, love.graphics.getHeight() + 24, 32, 24) imgFloor = love.graphics.newImage("examples/gfx/floor.png") imgFloor:setWrap("repeat", "repeat") diff --git a/lib/body.lua b/lib/body.lua index 7775319..8cd19ec 100644 --- a/lib/body.lua +++ b/lib/body.lua @@ -44,7 +44,7 @@ local function new(id, type, ...) util.drawto(circle_canvas, 0, 0, 1, function() love.graphics.circle('fill', args[3], args[3], args[3]) end) - obj.img = love.graphics.newImage(circle_canvas:getImageData()) + obj.img = love.graphics.newImage(circle_canvas:newImageData()) obj.imgWidth = obj.img:getWidth() obj.imgHeight = obj.img:getHeight() obj.ix = obj.imgWidth * 0.5 @@ -347,7 +347,7 @@ function body:setPoints(...) end if not self.img then - self.img = love.graphics.newImage(poly_canvas:getImageData()) + self.img = love.graphics.newImage(poly_canvas:newImageData()) self.imgWidth = self.img:getWidth() self.imgHeight = self.img:getHeight() self.ix = self.imgWidth * 0.5 @@ -434,7 +434,8 @@ function body:setNormalMap(normal, width, height, nx, ny) {self.normalWidth, self.normalHeight, self.normalWidth / self.normal:getWidth(), self.normalHeight / self.normal:getHeight()}, {0.0, self.normalHeight, 0.0, self.normalHeight / self.normal:getHeight()} } - self.normalMesh = love.graphics.newMesh(self.normalVert, self.normal, "fan") + self.normalMesh = love.graphics.newMesh(self.normalVert, "fan") + self.normalMesh:setTexture(self.normal) else self.normalMesh = nil end diff --git a/lib/init.lua b/lib/init.lua index 84425f9..6120631 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -67,7 +67,7 @@ local function new(options) end function light_world:refreshScreenSize(w, h) - w, h = w or love.window.getWidth(), h or love.window.getHeight() + w, h = w or love.graphics.getWidth(), h or love.graphics.getHeight() self.w, self.h = w, h self.render_buffer = love.graphics.newCanvas(w, h) @@ -108,8 +108,8 @@ end -- draw normal shading function light_world:drawShadows(l,t,w,h,s) -- create normal map - self.normalMap:clear() util.drawto(self.normalMap, l, t, s, function() + love.graphics.clear() for i = 1, #self.bodies do if self.bodies[i]:isVisible() then self.bodies[i]:drawNormal() @@ -120,20 +120,25 @@ function light_world:drawShadows(l,t,w,h,s) self.shadowShader:send('normalMap', self.normalMap) self.shadowShader:send("invert_normal", self.normalInvert == true) - self.shadow_buffer:clear() + love.graphics.setCanvas( self.shadow_buffer ) + love.graphics.clear() + love.graphics.setCanvas() for i = 1, #self.lights do local light = self.lights[i] if light:isVisible() then -- create shadow map for this light - self.shadowMap:clear() + love.graphics.setCanvas( self.shadowMap ) + love.graphics.clear() + love.graphics.setCanvas() util.drawto(self.shadowMap, l, t, s, function() --I dont know if it uses both or just calls both - love.graphics.setStencil(function() + love.graphics.stencil(function() local angle = light.direction - (light.angle / 2.0) love.graphics.arc("fill", light.x, light.y, light.range, angle, angle + light.angle) end) - love.graphics.setInvertedStencil(function() + love.graphics.stencil(function() love.graphics.setShader(self.image_mask) + -- TODO:invert mask for k = 1, #self.bodies do if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then self.bodies[k]:drawStencil() @@ -154,7 +159,7 @@ function light_world:drawShadows(l,t,w,h,s) self.shadowShader:send("lightSmooth", light.smooth) self.shadowShader:send("lightGlow", {1.0 - light.glowSize, light.glowStrength}) util.drawCanvasToCanvas(self.shadowMap, self.shadow_buffer, { - blendmode = 'additive', + blendmode = 'add', shader = self.shadowShader, stencil = function() local angle = light.direction - (light.angle / 2.0) @@ -166,13 +171,13 @@ function light_world:drawShadows(l,t,w,h,s) -- add in ambient color util.drawto(self.shadow_buffer, l, t, s, function() - love.graphics.setBlendMode("additive") + love.graphics.setBlendMode("add") love.graphics.setColor({self.ambient[1], self.ambient[2], self.ambient[3]}) love.graphics.rectangle("fill", -l/s, -t/s, w/s,h/s) end) self.post_shader:drawBlur(self.shadow_buffer, {self.shadowBlur}) - util.drawCanvasToCanvas(self.shadow_buffer, self.render_buffer, {blendmode = "multiplicative"}) + util.drawCanvasToCanvas(self.shadow_buffer, self.render_buffer, {blendmode = "multiply"}) end -- draw material @@ -198,7 +203,9 @@ function light_world:drawGlow(l,t,w,h,s) local has_glow = false -- create glow map - self.glowMap:clear(0, 0, 0) + love.graphics.setCanvas( self.glowMap ) + love.graphics.clear() + love.graphics.setCanvas() util.drawto(self.glowMap, l, t, s, function() for i = 1, #self.bodies do if self.bodies[i]:isVisible() and self.bodies[i].glowStrength > 0.0 then @@ -210,13 +217,15 @@ function light_world:drawGlow(l,t,w,h,s) if has_glow then self.post_shader:drawBlur(self.glowMap, {self.glowBlur}) - util.drawCanvasToCanvas(self.glowMap, self.render_buffer, {blendmode = "additive"}) + util.drawCanvasToCanvas(self.glowMap, self.render_buffer, {blendmode = "add"}) end end -- draw refraction function light_world:drawRefraction(l,t,w,h,s) -- create refraction map - self.refractionMap:clear() + love.graphics.setCanvas( self.refractionMap ) + love.graphics.clear() + love.graphics.setCanvas() util.drawto(self.refractionMap, l, t, s, function() for i = 1, #self.bodies do if self.bodies[i]:isVisible() then @@ -233,7 +242,9 @@ end -- draw reflection function light_world:drawReflection(l,t,w,h,s) -- create reflection map - self.reflectionMap:clear(0, 0, 0) + love.graphics.setCanvas( self.reflectionMap ) + love.graphics.clear() + love.graphics.setCanvas() util.drawto(self.reflectionMap, l, t, s, function() for i = 1, #self.bodies do if self.bodies[i]:isVisible() then diff --git a/lib/postshader.lua b/lib/postshader.lua index 1c06861..0f7bd4b 100644 --- a/lib/postshader.lua +++ b/lib/postshader.lua @@ -52,7 +52,7 @@ local function new() end function post_shader:refreshScreenSize(w, h) - w, h = w or love.window.getWidth(), h or love.window.getHeight() + w, h = w or love.graphics.getWidth(), h or love.graphics.getHeight() self.back_buffer = love.graphics.newCanvas(w, h) end diff --git a/lib/util.lua b/lib/util.lua index 48b71da..4dcc277 100644 --- a/lib/util.lua +++ b/lib/util.lua @@ -1,6 +1,8 @@ local util = {} +--TODO: the whole stencil/canvas system should be reviewed since it has been changed in a naive way function util.process(canvas, options) + --TODO: now you cannot draw a canvas to itself util.drawCanvasToCanvas(canvas, canvas, options) end @@ -15,17 +17,21 @@ function util.drawCanvasToCanvas(canvas, other_canvas, options) love.graphics.setShader(options["shader"]) end if options["stencil"] then - love.graphics.setStencil(options["stencil"]) + love.graphics.stencil(options["stencil"]) end if options["istencil"] then - love.graphics.setInvertedStencil(options["istencil"]) + love.graphics.stencil(options["istencil"]) + --TODO: invert map end if options["color"] then love.graphics.setColor(unpack(options["color"])) else love.graphics.setColor(255,255,255) end + --TODO: not really sure if this is right + love.graphics.setCanvas() love.graphics.draw(canvas,0,0) + love.graphics.setCanvas(canvas) if options["blendmode"] then love.graphics.setBlendMode("alpha") end @@ -33,10 +39,12 @@ function util.drawCanvasToCanvas(canvas, other_canvas, options) love.graphics.setShader() end if options["stencil"] then - love.graphics.setStencil() + --TODO: check if commenting this is really ok + --love.graphics.stencil() end if options["istencil"] then - love.graphics.setInvertedStencil() + --TODO: check if commenting this is really ok + --love.graphics.setInvertedStencil() end end) end diff --git a/main.lua b/main.lua index 7ad3133..000feff 100644 --- a/main.lua +++ b/main.lua @@ -5,7 +5,6 @@ -- All examples in one application! Yaay! -- -- Updated by Dresenpai - require "lib/postshader" local LightWorld = require "lib" local ProFi = require 'examples.vendor.ProFi' @@ -17,8 +16,8 @@ exf.available = {} function love.load() exf.list = List:new() - exf.smallfont = love.graphics.newFont(love._vera_ttf,12) - exf.bigfont = love.graphics.newFont(love._vera_ttf, 24) + exf.smallfont = love.graphics.newFont(12) + exf.bigfont = love.graphics.newFont(24) exf.list.font = exf.smallfont exf.bigball = love.graphics.newImage("examples/gfx/love-big-ball.png") @@ -65,7 +64,7 @@ function exf.draw() love.graphics.setBackgroundColor(0, 0, 0) love.graphics.setColor(48, 156, 225) - love.graphics.rectangle("fill", 0, 0, love.window.getWidth(), love.window.getHeight()) + love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()) love.graphics.setColor(255, 255, 255, 191) love.graphics.setFont(exf.bigfont) @@ -281,7 +280,7 @@ end function List:mousepressed(mx, my, b) if self:hasBar() then - if b == "l" then + if b == 1 then local x, y, w, h = self:getBarRect() if inside(mx, my, x, y, w, h) then self.bar_lock = { x = mx, y = my } @@ -304,7 +303,7 @@ function List:mousepressed(mx, my, b) end end - if b == "l" and inside(mx, my, self.x+2, self.y+1, self.width-3, self.height-3) then + if b == 1 and inside(mx, my, self.x+2, self.y+1, self.width-3, self.height-3) then local tx, ty = mx-self.x, my + self:getOffset() - self.y local index = math.floor((ty/self.sum_item_height)*self.items.n) local i = self.items[index+1] @@ -317,7 +316,7 @@ end function List:mousereleased(x, y, b) if self:hasBar() then - if b == "l" then + if b == 1 then self.bar_lock = nil end end From eeb9d917471593a248e98f4ffd7f0ee3e8c363e5 Mon Sep 17 00:00:00 2001 From: leokaplan Date: Thu, 4 Feb 2016 17:33:22 +0100 Subject: [PATCH 2/4] minor fixes over stencil --- lib/init.lua | 9 ++++++--- lib/util.lua | 18 +++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/init.lua b/lib/init.lua index 6120631..5738fac 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -107,9 +107,10 @@ end -- draw normal shading function light_world:drawShadows(l,t,w,h,s) - -- create normal map + love.graphics.setCanvas( self.normalMap ) + love.graphics.clear() + love.graphics.setCanvas() util.drawto(self.normalMap, l, t, s, function() - love.graphics.clear() for i = 1, #self.bodies do if self.bodies[i]:isVisible() then self.bodies[i]:drawNormal() @@ -136,9 +137,9 @@ function light_world:drawShadows(l,t,w,h,s) local angle = light.direction - (light.angle / 2.0) love.graphics.arc("fill", light.x, light.y, light.range, angle, angle + light.angle) end) + love.graphics.setStencilTest("greater",0) love.graphics.stencil(function() love.graphics.setShader(self.image_mask) - -- TODO:invert mask for k = 1, #self.bodies do if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then self.bodies[k]:drawStencil() @@ -146,6 +147,7 @@ function light_world:drawShadows(l,t,w,h,s) end love.graphics.setShader() end) + love.graphics.setStencilTest("equal", 0) for k = 1, #self.bodies do if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then self.bodies[k]:drawShadow(light) @@ -178,6 +180,7 @@ function light_world:drawShadows(l,t,w,h,s) self.post_shader:drawBlur(self.shadow_buffer, {self.shadowBlur}) util.drawCanvasToCanvas(self.shadow_buffer, self.render_buffer, {blendmode = "multiply"}) + love.graphics.setStencilTest() end -- draw material diff --git a/lib/util.lua b/lib/util.lua index 4dcc277..5d16bae 100644 --- a/lib/util.lua +++ b/lib/util.lua @@ -18,33 +18,29 @@ function util.drawCanvasToCanvas(canvas, other_canvas, options) end if options["stencil"] then love.graphics.stencil(options["stencil"]) + love.graphics.setStencilTest("greater",0) end if options["istencil"] then love.graphics.stencil(options["istencil"]) - --TODO: invert map + love.graphics.setStencilTest("equal", 0) end if options["color"] then love.graphics.setColor(unpack(options["color"])) else love.graphics.setColor(255,255,255) end - --TODO: not really sure if this is right - love.graphics.setCanvas() - love.graphics.draw(canvas,0,0) - love.graphics.setCanvas(canvas) + if love.graphics.getCanvas() ~= canvas then + love.graphics.draw(canvas,0,0) + end if options["blendmode"] then love.graphics.setBlendMode("alpha") end if options["shader"] then love.graphics.setShader() end - if options["stencil"] then - --TODO: check if commenting this is really ok - --love.graphics.stencil() - end - if options["istencil"] then - --TODO: check if commenting this is really ok + if options["stencil"] or options["istencil"] then --love.graphics.setInvertedStencil() + love.graphics.setStencilTest() end end) end From f68746c10872853d0f8a958265ac8de75b6c4c2c Mon Sep 17 00:00:00 2001 From: Leonardo Kaplan Date: Sun, 24 Apr 2016 15:38:59 +0200 Subject: [PATCH 3/4] two canvas --- lib/util.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/util.lua b/lib/util.lua index 5d16bae..7da2d50 100644 --- a/lib/util.lua +++ b/lib/util.lua @@ -3,7 +3,9 @@ local util = {} function util.process(canvas, options) --TODO: now you cannot draw a canvas to itself - util.drawCanvasToCanvas(canvas, canvas, options) + temp = love.graphics.newCanvas() + util.drawCanvasToCanvas(canvas, temp, options) + util.drawCanvasToCanvas(temp, canvas, options) end function util.drawCanvasToCanvas(canvas, other_canvas, options) From f0f3b8812c460adee71689d50eec282d34ed97ba Mon Sep 17 00:00:00 2001 From: Leonardo Kaplan Date: Sun, 24 Apr 2016 16:09:51 +0200 Subject: [PATCH 4/4] ligth y fix --- lib/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/init.lua b/lib/init.lua index 5738fac..130f1a1 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -156,7 +156,7 @@ function light_world:drawShadows(l,t,w,h,s) end) -- draw scene for this light using normals and shadowmap self.shadowShader:send('lightColor', {light.red / 255.0, light.green / 255.0, light.blue / 255.0}) - self.shadowShader:send("lightPosition", {(light.x + l/s) * s, (h/s - (light.y + t/s)) * s, (light.z * 10) / 255.0}) + self.shadowShader:send("lightPosition", {(light.x + l/s) * s, (light.y + t/s) * s, (light.z * 10) / 255.0}) self.shadowShader:send('lightRange',{light.range * s}) self.shadowShader:send("lightSmooth", light.smooth) self.shadowShader:send("lightGlow", {1.0 - light.glowSize, light.glowStrength})