Merge pull request #43 from xiejiangzhi/master

love11.2 It's based on other PRs
This commit is contained in:
Tim Anema 2019-09-09 09:16:45 -04:00 committed by GitHub
commit 7c0d9a604b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 223 additions and 186 deletions

View File

@ -1,6 +1,6 @@
function love.conf(t) function love.conf(t)
t.identity = nil -- The name of the save directory (string) t.identity = nil -- The name of the save directory (string)
t.version = "0.10.0" -- The LÖVE version this game was made for (string) t.version = "11.2" -- The LÖVE version this game was made for (string)
t.console = true -- Attach a console (boolean, Windows only) t.console = true -- Attach a console (boolean, Windows only)
t.window.title = "Untitled" -- The window title (string) t.window.title = "Untitled" -- The window title (string)

View File

@ -96,7 +96,7 @@ function love.load()
shadowBlur = 2.0 shadowBlur = 2.0
}) })
mouseLight = lightWorld:newLight(0, 0, 255, 191, 127, lightRange) mouseLight = lightWorld:newLight(0, 0, 1, 191/ 255, 0.5, lightRange)
mouseLight:setGlowStrength(0.3) mouseLight:setGlowStrength(0.3)
mouseLight:setSmooth(lightSmooth) mouseLight:setSmooth(lightSmooth)
mouseLight.z = 63 mouseLight.z = 63
@ -199,10 +199,10 @@ function love.draw()
lightWorld:draw(function(l, t, w, h, s) lightWorld:draw(function(l, t, w, h, s)
love.graphics.setBlendMode("alpha") love.graphics.setBlendMode("alpha")
if normalOn then if normalOn then
love.graphics.setColor(127, 127, 255) love.graphics.setColor(0.5, 0.5, 1)
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()) love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
else else
love.graphics.setColor(255, 255, 255) love.graphics.setColor(1, 1, 1)
if textureOn then if textureOn then
love.graphics.draw(imgFloor, quadScreen, 0,0) love.graphics.draw(imgFloor, quadScreen, 0,0)
else else
@ -214,7 +214,7 @@ function love.draw()
if phyLight[i]:getType() == "refraction" then if phyLight[i]:getType() == "refraction" then
if not normalOn then if not normalOn then
love.graphics.setBlendMode("alpha") love.graphics.setBlendMode("alpha")
love.graphics.setColor(255, 255, 255, 191) love.graphics.setColor(1, 1, 1, 191/255)
love.graphics.draw(water, phyLight[i].x - phyLight[i].ox, phyLight[i].y - phyLight[i].oy) love.graphics.draw(water, phyLight[i].x - phyLight[i].ox, phyLight[i].y - phyLight[i].oy)
end end
end end
@ -224,20 +224,22 @@ function love.draw()
for i = 1, phyCnt do for i = 1, phyCnt do
if phyLight[i]:getType() == "polygon" then if phyLight[i]:getType() == "polygon" then
math.randomseed(i) math.randomseed(i)
love.graphics.setColor(math.random(0, 255), math.random(0, 255), math.random(0, 255)) love.graphics.setColor(math.random(), math.random(), math.random())
love.graphics.polygon("fill", phyLight[i]:getPoints()) love.graphics.polygon("fill", phyLight[i]:getPoints())
elseif phyLight[i]:getType() == "circle" then elseif phyLight[i]:getType() == "circle" then
math.randomseed(i) math.randomseed(i)
love.graphics.setColor(math.random(0, 255), math.random(0, 255), math.random(0, 255)) love.graphics.setColor(math.random(), math.random(), math.random())
local cx, cy = phyLight[i]:getPosition() local cx, cy = phyLight[i]:getPosition()
love.graphics.circle("fill", cx, cy, phyLight[i]:getRadius()) love.graphics.circle("fill", cx, cy, phyLight[i]:getRadius())
elseif phyLight[i]:getType() == "image" then elseif phyLight[i]:getType() == "image" then
if normalOn and phyLight[i].normal then if normalOn and phyLight[i].normal then
love.graphics.setColor(255, 255, 255) love.graphics.setColor(1, 1, 1)
love.graphics.draw(phyLight[i].normal, phyLight[i].x - phyLight[i].nx, phyLight[i].y - phyLight[i].ny) love.graphics.draw(phyLight[i].normal, phyLight[i].x - phyLight[i].nx, phyLight[i].y - phyLight[i].ny)
elseif not phyLight[i].material then elseif not phyLight[i].material then
math.randomseed(i) math.randomseed(i)
love.graphics.setColor(math.random(127, 255), math.random(127, 255), math.random(127, 255)) love.graphics.setColor(
math.random(127, 255) / 255, math.random(127, 255)/ 255, math.random(127, 255) / 255
)
love.graphics.draw(phyLight[i].img, phyLight[i].x - phyLight[i].ix, phyLight[i].y - phyLight[i].iy) love.graphics.draw(phyLight[i].img, phyLight[i].x - phyLight[i].ix, phyLight[i].y - phyLight[i].iy)
end end
end end
@ -254,65 +256,65 @@ function love.draw()
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), 44) love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), 44)
love.graphics.rectangle("fill", 0, love.graphics.getHeight() - 68, 240, 68) love.graphics.rectangle("fill", 0, love.graphics.getHeight() - 68, 240, 68)
love.graphics.rectangle("fill", love.graphics.getWidth() - 244, love.graphics.getHeight() - 84, 244, 84) love.graphics.rectangle("fill", love.graphics.getWidth() - 244, love.graphics.getHeight() - 84, 244, 84)
love.graphics.setColor(0, 255, 0) love.graphics.setColor(0, 1, 0)
love.graphics.print("F1: Help (on)", 4 + 152 * 0, 4) love.graphics.print("F1: Help (on)", 4 + 152 * 0, 4)
if shadowBlur >= 1.0 then if shadowBlur >= 1.0 then
love.graphics.setColor(0, 255, 0) love.graphics.setColor(0, 1, 0)
love.graphics.print("F5: Shadowblur (" .. shadowBlur .. ")", 4 + 152 * 4, 4) love.graphics.print("F5: Shadowblur (" .. shadowBlur .. ")", 4 + 152 * 4, 4)
else else
love.graphics.setColor(255, 0, 0) love.graphics.setColor(1, 0, 0)
love.graphics.print("F5: Shadowblur (off)", 4 + 152 * 4, 4) love.graphics.print("F5: Shadowblur (off)", 4 + 152 * 4, 4)
end end
if bloomOn > 0.0 then if bloomOn > 0.0 then
love.graphics.setColor(0, 255, 0) love.graphics.setColor(0, 1, 0)
love.graphics.print("F6: Bloom (" .. (bloomOn * 4) .. ")", 4 + 152 * 0, 4 + 20 * 1) love.graphics.print("F6: Bloom (" .. (bloomOn * 4) .. ")", 4 + 152 * 0, 4 + 20 * 1)
else else
love.graphics.setColor(255, 0, 0) love.graphics.setColor(1, 0, 0)
love.graphics.print("F6: Bloom (off)", 4 + 152 * 0, 4 + 20 * 1) love.graphics.print("F6: Bloom (off)", 4 + 152 * 0, 4 + 20 * 1)
end end
if textureOn then if textureOn then
love.graphics.setColor(0, 255, 0) love.graphics.setColor(0, 1, 0)
love.graphics.print("F7: Texture (on)", 4 + 152 * 1, 4 + 20 * 1) love.graphics.print("F7: Texture (on)", 4 + 152 * 1, 4 + 20 * 1)
else else
love.graphics.setColor(255, 0, 0) love.graphics.setColor(1, 0, 0)
love.graphics.print("F7: Texture (off)", 4 + 152 * 1, 4 + 20 * 1) love.graphics.print("F7: Texture (off)", 4 + 152 * 1, 4 + 20 * 1)
end end
if normalOn then if normalOn then
love.graphics.setColor(0, 255, 0) love.graphics.setColor(0, 1, 0)
love.graphics.print("F8: Normal (on)", 4 + 152 * 2, 4 + 20 * 1) love.graphics.print("F8: Normal (on)", 4 + 152 * 2, 4 + 20 * 1)
else else
love.graphics.setColor(255, 0, 0) love.graphics.setColor(1, 0, 0)
love.graphics.print("F8: Normal (off)", 4 + 152 * 2, 4 + 20 * 1) love.graphics.print("F8: Normal (off)", 4 + 152 * 2, 4 + 20 * 1)
end end
if glowBlur >= 1.0 then if glowBlur >= 1.0 then
love.graphics.setColor(0, 255, 0) love.graphics.setColor(0, 1, 0)
love.graphics.print("F9: Glow Blur (" .. glowBlur .. ")", 4 + 152 * 3, 4 + 20 * 1) love.graphics.print("F9: Glow Blur (" .. glowBlur .. ")", 4 + 152 * 3, 4 + 20 * 1)
else else
love.graphics.setColor(255, 0, 0) love.graphics.setColor(1, 0, 0)
love.graphics.print("F9: Glow Blur (off)", 4 + 152 * 3, 4 + 20 * 1) love.graphics.print("F9: Glow Blur (off)", 4 + 152 * 3, 4 + 20 * 1)
end end
if effectOn >= 1.0 then if effectOn >= 1.0 then
love.graphics.setColor(0, 255, 0) love.graphics.setColor(0, 1, 0)
love.graphics.print("F10: Effects (" .. effectOn .. ")", 4 + 152 * 4, 4 + 20 * 1) love.graphics.print("F10: Effects (" .. effectOn .. ")", 4 + 152 * 4, 4 + 20 * 1)
else else
love.graphics.setColor(255, 0, 0) love.graphics.setColor(1, 0, 0)
love.graphics.print("F10: Effects (off)", 4 + 152 * 4, 4 + 20 * 1) love.graphics.print("F10: Effects (off)", 4 + 152 * 4, 4 + 20 * 1)
end end
love.graphics.setColor(255, 0, 255) love.graphics.setColor(1, 0, 1)
love.graphics.print("F11: Clear obj.", 4 + 152 * 4, 4 + 20 * 2) love.graphics.print("F11: Clear obj.", 4 + 152 * 4, 4 + 20 * 2)
love.graphics.print("F12: Clear lights", 4 + 152 * 4, 4 + 20 * 3) love.graphics.print("F12: Clear lights", 4 + 152 * 4, 4 + 20 * 3)
love.graphics.setColor(0, 127, 255) love.graphics.setColor(0, 0.5, 1)
love.graphics.print("WASD Keys: Move objects", 4, love.graphics.getHeight() - 20 * 3) love.graphics.print("WASD Keys: Move objects", 4, love.graphics.getHeight() - 20 * 3)
love.graphics.print("Arrow Keys: Move map", 4, love.graphics.getHeight() - 20 * 2) love.graphics.print("Arrow Keys: Move map", 4, love.graphics.getHeight() - 20 * 2)
love.graphics.print("0-9 Keys: Add object", 4, love.graphics.getHeight() - 20 * 1) love.graphics.print("0-9 Keys: Add object", 4, love.graphics.getHeight() - 20 * 1)
love.graphics.setColor(255, 127, 0) love.graphics.setColor(1, 0.5, 0)
love.graphics.print("M.left: Add cube", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 4) love.graphics.print("M.left: Add cube", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 4)
love.graphics.print("M.middle: Add light", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 3) love.graphics.print("M.middle: Add light", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 3)
love.graphics.print("M.right: Add circle", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 2) love.graphics.print("M.right: Add circle", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 2)
love.graphics.print("M.scroll: Change smooth", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 1) love.graphics.print("M.scroll: Change smooth", love.graphics.getWidth() - 240, love.graphics.getHeight() - 20 * 1)
love.graphics.setColor(255, 127, 0) love.graphics.setColor(1, 0.5, 0)
else else
love.graphics.setColor(255, 255, 255, 191) love.graphics.setColor(1, 1, 1, 191/255)
love.graphics.print("F1: Help", 4, 4) love.graphics.print("F1: Help", 4, 4)
end end
end end
@ -324,11 +326,11 @@ function love.mousepressed(x, y, c)
local light local light
if r == 0 then if r == 0 then
light = lightWorld:newLight(x, y, 31, 127, 63, lightRange) light = lightWorld:newLight(x, y, 31/ 255, 0.5, 63/ 255, lightRange)
elseif r == 1 then elseif r == 1 then
light = lightWorld:newLight(x, y, 127, 63, 31, lightRange) light = lightWorld:newLight(x, y, 0.5, 63/255, 31/255, lightRange)
else else
light = lightWorld:newLight(x, y, 31, 63, 127, lightRange) light = lightWorld:newLight(x, y, 31/255, 63/255, 127/255, lightRange)
end end
light:setSmooth(lightSmooth) light:setSmooth(lightSmooth)
light:setGlowStrength(0.3) light:setGlowStrength(0.3)
@ -424,7 +426,7 @@ function love.keypressed(k, u)
initScene() initScene()
elseif k == "f12" then elseif k == "f12" then
lightWorld:clearLights() lightWorld:clearLights()
mouseLight = lightWorld:newLight(0, 0, 255, 191, 127, lightRange) mouseLight = lightWorld:newLight(0, 0, 1, 191/255, 0.5, lightRange)
mouseLight:setGlowStrength(0.3) mouseLight:setGlowStrength(0.3)
mouseLight:setSmooth(lightSmooth) mouseLight:setSmooth(lightSmooth)
elseif k == "1" then elseif k == "1" then
@ -498,7 +500,7 @@ function love.keypressed(k, u)
phyCnt = phyCnt + 1 phyCnt = phyCnt + 1
phyLight[phyCnt] = lightWorld:newImage(blopp, mx, my, 42, 16, 21, 0) phyLight[phyCnt] = lightWorld:newImage(blopp, mx, my, 42, 16, 21, 0)
phyLight[phyCnt]:generateNormalMapGradient("gradient", "gradient") phyLight[phyCnt]:generateNormalMapGradient("gradient", "gradient")
phyLight[phyCnt]:setAlpha(255 * 0.5) phyLight[phyCnt]:setAlpha(0.5)
elseif k == "7" then elseif k == "7" then
-- add image -- add image
phyCnt = phyCnt + 1 phyCnt = phyCnt + 1
@ -517,24 +519,24 @@ function love.keypressed(k, u)
mx+w, my+h, mx+w, my+h,
mx, my+h mx, my+h
) )
phyLight[phyCnt]:setAlpha(255 * 0.5) phyLight[phyCnt]:setAlpha(0.5)
phyLight[phyCnt]:setGlowStrength(1.0) phyLight[phyCnt]:setGlowStrength(1.0)
math.randomseed(phyCnt) math.randomseed(phyCnt)
phyLight[phyCnt]:setGlowColor(math.random(0, 255), math.random(0, 255), math.random(0, 255)) phyLight[phyCnt]:setGlowColor(math.random(), math.random(), math.random())
math.randomseed(phyCnt) math.randomseed(phyCnt)
phyLight[phyCnt]:setColor(math.random(0, 255), math.random(0, 255), math.random(0, 255)) phyLight[phyCnt]:setColor(math.random(), math.random(), math.random())
elseif k == "9" then elseif k == "9" then
-- add circle -- add circle
math.randomseed(love.timer.getTime()) math.randomseed(love.timer.getTime())
cRadius = math.random(8, 32) cRadius = math.random(8, 32)
phyCnt = phyCnt + 1 phyCnt = phyCnt + 1
phyLight[phyCnt] = lightWorld:newCircle(mx, my, cRadius) phyLight[phyCnt] = lightWorld:newCircle(mx, my, cRadius)
phyLight[phyCnt]:setAlpha(255 * 0.5) phyLight[phyCnt]:setAlpha(0.5)
phyLight[phyCnt]:setGlowStrength(1.0) phyLight[phyCnt]:setGlowStrength(1.0)
math.randomseed(phyCnt) math.randomseed(phyCnt)
phyLight[phyCnt]:setGlowColor(math.random(0, 255), math.random(0, 255), math.random(0, 255)) phyLight[phyCnt]:setGlowColor(math.random(), math.random(), math.random())
math.randomseed(phyCnt) math.randomseed(phyCnt)
phyLight[phyCnt]:setColor(math.random(0, 255), math.random(0, 255), math.random(0, 255)) phyLight[phyCnt]:setColor(math.random(), math.random(), math.random())
elseif k == "0" then elseif k == "0" then
phyCnt = phyCnt + 1 phyCnt = phyCnt + 1
phyLight[phyCnt] = lightWorld:newRefraction(refraction_normal, mx, my) phyLight[phyCnt] = lightWorld:newRefraction(refraction_normal, mx, my)
@ -545,11 +547,11 @@ function love.keypressed(k, u)
local light local light
if r == 0 then if r == 0 then
light = lightWorld:newLight(mx, my, 31, 127, 63, lightRange) light = lightWorld:newLight(mx, my, 31/255, 127 / 255, 63 / 255, lightRange)
elseif r == 1 then elseif r == 1 then
light = lightWorld:newLight(mx, my, 127, 63, 31, lightRange) light = lightWorld:newLight(mx, my, 127 / 255, 63 / 255, 31 / 255, lightRange)
else else
light = lightWorld:newLight(mx, my, 31, 63, 127, lightRange) light = lightWorld:newLight(mx, my, 31 / 255, 63 / 255, 127 / 255, lightRange)
end end
light:setSmooth(lightSmooth) light:setSmooth(lightSmooth)
light:setGlowStrength(0.3) light:setGlowStrength(0.3)
@ -559,9 +561,9 @@ function love.keypressed(k, u)
local light local light
if r == 0 then if r == 0 then
light = lightWorld:newLight(mx, my, 31, 127, 63, lightRange) light = lightWorld:newLight(mx, my, 31/255, 127/255, 63/255, lightRange)
elseif r == 1 then elseif r == 1 then
light = lightWorld:newLight(mx, my, 127, 63, 31, lightRange) light = lightWorld:newLight(mx, my, 127/255, 63/255, 31/255, lightRange)
else else
light = lightWorld:newLight(mx, my, 31, 63, 127, lightRange) light = lightWorld:newLight(mx, my, 31, 63, 127, lightRange)
end end

View File

@ -70,13 +70,13 @@ end
function love.draw() function love.draw()
cam:attach() cam:attach()
lightWorld:draw(function() lightWorld:draw(function()
love.graphics.setColor(255, 255, 255) love.graphics.setColor(1, 1, 1)
love.graphics.rectangle("fill", -x/scale, -y/scale, love.graphics.getWidth()/scale, love.graphics.getHeight()/scale) love.graphics.rectangle("fill", -x/scale, -y/scale, love.graphics.getWidth()/scale, love.graphics.getHeight()/scale)
love.graphics.setColor(63, 255, 127) love.graphics.setColor(63/ 255, 1, 0.5)
local cx, cy = circleTest:getPosition() local cx, cy = circleTest:getPosition()
love.graphics.circle("fill", cx, cy, circleTest:getRadius()) love.graphics.circle("fill", cx, cy, circleTest:getRadius())
love.graphics.polygon("fill", rectangleTest:getPoints()) love.graphics.polygon("fill", rectangleTest:getPoints())
love.graphics.setColor(255, 255, 255) love.graphics.setColor(1, 1, 1)
love.graphics.draw(image, 64 - image:getWidth() * 0.5, 64 - image:getHeight() * 0.5) love.graphics.draw(image, 64 - image:getWidth() * 0.5, 64 - image:getHeight() * 0.5)
end) end)
cam:detach() cam:detach()

View File

@ -20,9 +20,9 @@ local function new(id, type, ...)
obj.green = 1.0 obj.green = 1.0
obj.blue = 1.0 obj.blue = 1.0
obj.alpha = 1.0 obj.alpha = 1.0
obj.glowRed = 255 obj.glowRed = 1
obj.glowGreen = 255 obj.glowGreen = 1
obj.glowBlue = 255 obj.glowBlue = 1
obj.glowStrength = 0.0 obj.glowStrength = 0.0
obj.tileX = 0 obj.tileX = 0
obj.tileY = 0 obj.tileY = 0
@ -41,7 +41,7 @@ local function new(id, type, ...)
obj.y = args[2] or 0 obj.y = args[2] or 0
circle_canvas = love.graphics.newCanvas(args[3]*2, args[3]*2) circle_canvas = love.graphics.newCanvas(args[3]*2, args[3]*2)
util.drawto(circle_canvas, 0, 0, 1, function() util.drawto(circle_canvas, 0, 0, 1, false, function()
love.graphics.circle('fill', args[3], args[3], args[3]) love.graphics.circle('fill', args[3], args[3], args[3])
end) end)
obj.img = love.graphics.newImage(circle_canvas:newImageData()) obj.img = love.graphics.newImage(circle_canvas:newImageData())
@ -286,10 +286,14 @@ function body:setNormalOffset(nx, ny)
end end
-- set glow color -- set glow color
function body:setGlowColor(red, green, blue) function body:setGlowColor(r, g, b)
self.glowRed = red if r > 1 then r = r / 255 end
self.glowGreen = green if g > 1 then g = r / 255 end
self.glowBlue = blue if b > 1 then b = r / 255 end
self.glowRed = r
self.glowGreen = g
self.glowBlue = b
end end
-- set glow alpha -- set glow alpha
@ -337,7 +341,7 @@ function body:setPoints(...)
self.y = self.y + (self.height * 0.5) self.y = self.y + (self.height * 0.5)
local poly_canvas = love.graphics.newCanvas(self.width, self.height) local poly_canvas = love.graphics.newCanvas(self.width, self.height)
util.drawto(poly_canvas, 0, 0, 1, function() util.drawto(poly_canvas, 0, 0, 1, false, function()
love.graphics.polygon('fill', self.unit_data) love.graphics.polygon('fill', self.unit_data)
end) end)
@ -377,10 +381,10 @@ function body:setShine(b)
end end
-- set glass color -- set glass color
function body:setColor(red, green, blue) function body:setColor(r, g, b)
self.red = red self.red = r
self.green = green self.green = g
self.blue = blue self.blue = b
end end
-- set glass alpha -- set glass alpha
@ -569,7 +573,7 @@ end
function body:drawNormal() function body:drawNormal()
if not self.refraction and not self.reflection and self.normalMesh then if not self.refraction and not self.reflection and self.normalMesh then
love.graphics.setColor(255, 255, 255) love.graphics.setColor(1, 1, 1)
if self.type == 'animation' then if self.type == 'animation' then
self.animation:draw(self.normal, self.x, self.y, self.rotation, self.scalex, self.scaley, self.nx, self.ny) self.animation:draw(self.normal, self.x, self.y, self.rotation, self.scalex, self.scaley, self.nx, self.ny)
else else
@ -579,7 +583,9 @@ function body:drawNormal()
end end
function body:drawGlow() function body:drawGlow()
love.graphics.setColor(self.glowRed * self.glowStrength, self.glowGreen * self.glowStrength, self.glowBlue * self.glowStrength) love.graphics.setColor(
self.glowRed * self.glowStrength, self.glowGreen * self.glowStrength, self.glowBlue * self.glowStrength
)
if self.type == "circle" then if self.type == "circle" then
love.graphics.circle("fill", self.x, self.y, self.radius * self.scalex) love.graphics.circle("fill", self.x, self.y, self.radius * self.scalex)
@ -590,7 +596,7 @@ function body:drawGlow()
love.graphics.setShader(self.glowShader) love.graphics.setShader(self.glowShader)
self.glowShader:send("glowImage", self.glow) self.glowShader:send("glowImage", self.glow)
self.glowShader:send("glowTime", love.timer.getTime() * 0.5) self.glowShader:send("glowTime", love.timer.getTime() * 0.5)
love.graphics.setColor(255, 255, 255) love.graphics.setColor(1, 1, 1)
else else
love.graphics.setColor(0, 0, 0) love.graphics.setColor(0, 0, 0)
end end
@ -607,7 +613,7 @@ end
function body:drawRefraction() function body:drawRefraction()
if self.refraction and self.normal then if self.refraction and self.normal then
love.graphics.setColor(255, 255, 255) love.graphics.setColor(1, 1, 1)
if self.tileX == 0.0 and self.tileY == 0.0 then if self.tileX == 0.0 and self.tileY == 0.0 then
love.graphics.draw(self.normal, self.x, self.y, self.rotation, self.scalex, self.scaley, self.nx, self.ny) love.graphics.draw(self.normal, self.x, self.y, self.rotation, self.scalex, self.scaley, self.nx, self.ny)
else else
@ -633,12 +639,12 @@ end
function body:drawReflection() function body:drawReflection()
if self.reflection and self.normal then if self.reflection and self.normal then
love.graphics.setColor(255, 0, 0) love.graphics.setColor(1, 0, 0)
self.normalMesh:setVertices(self.normalVert) self.normalMesh:setVertices(self.normalVert)
love.graphics.draw(self.normalMesh, self.x, self.y, self.rotation, self.scalex, self.scaley, self.nx, self.ny) love.graphics.draw(self.normalMesh, self.x, self.y, self.rotation, self.scalex, self.scaley, self.nx, self.ny)
end end
if self.reflective and self.img then if self.reflective and self.img then
love.graphics.setColor(0, 255, 0) love.graphics.setColor(0, 1, 0)
if self.type == 'animation' then if self.type == 'animation' then
self.animation:draw(self.img, self.x, self.y, self.rotation, self.scalex, self.scaley, self.ix, self.iy) self.animation:draw(self.img, self.x, self.y, self.rotation, self.scalex, self.scaley, self.ix, self.iy)
else else
@ -657,7 +663,7 @@ end
function body:drawMaterial() function body:drawMaterial()
if self.material and self.normal then if self.material and self.normal then
love.graphics.setShader(self.materialShader) love.graphics.setShader(self.materialShader)
love.graphics.setColor(255, 255, 255) love.graphics.setColor(1, 1, 1)
self.materialShader:send("material", self.material) self.materialShader:send("material", self.material)
if self.type == 'animation' then if self.type == 'animation' then
self.animation:draw(self.normal, self.x, self.y, self.rotation, self.scalex, self.scaley, self.nx, self.ny) self.animation:draw(self.normal, self.x, self.y, self.rotation, self.scalex, self.scaley, self.nx, self.ny)
@ -679,7 +685,7 @@ function body:drawShadow(light)
return return
end end
love.graphics.setColor(self.red, self.green, self.blue, self.alpha) love.graphics.setColor(self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255)
if self.shadowType == "polygon" then if self.shadowType == "polygon" then
self:drawPolyShadow(light) self:drawPolyShadow(light)
elseif self.shadowType == "circle" then elseif self.shadowType == "circle" then
@ -769,10 +775,10 @@ function body:drawImageShadow(light)
local shadowY = (length * math.cos(shadowRotation) + 1.0) * shadowStartY local shadowY = (length * math.cos(shadowRotation) + 1.0) * shadowStartY
self.shadowMesh:setVertices({ self.shadowMesh:setVertices({
{shadowX, shadowY, 0, 0, self.red, self.green, self.blue, self.alpha}, {shadowX, shadowY, 0, 0, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255},
{shadowX + self.imgWidth, shadowY, 1, 0, self.red, self.green, self.blue, self.alpha}, {shadowX + self.imgWidth, shadowY, 1, 0, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255},
{self.imgWidth, shadowStartY, 1, 1, self.red, self.green, self.blue, self.alpha}, {self.imgWidth, shadowStartY, 1, 1, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255},
{0, shadowStartY, 0, 1, self.red, self.green, self.blue, self.alpha} {0, shadowStartY, 0, 1, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255}
}) })
love.graphics.draw(self.shadowMesh, self.x, self.y, self.rotation, self.scalex, self.scaley, self.ox, self.oy) love.graphics.draw(self.shadowMesh, self.x, self.y, self.rotation, self.scalex, self.scaley, self.ox, self.oy)

View File

@ -59,6 +59,7 @@ local function new(options)
options = options or {} options = options or {}
for k, v in pairs(options) do obj[k] = v end for k, v in pairs(options) do obj[k] = v end
for i, v in ipairs(obj.ambient) do if v > 1 then obj.ambient[i] = v / 255 end end
local world = setmetatable(obj, light_world) local world = setmetatable(obj, light_world)
world:refreshScreenSize() world:refreshScreenSize()
@ -94,8 +95,8 @@ function light_world:update(dt)
end end
function light_world:draw(cb) function light_world:draw(cb)
util.drawto(self.render_buffer, self.l, self.t, self.s, function() util.drawto(self.render_buffer, self.l, self.t, self.s, false, function()
cb( self.l,self.t,self.w,self.h,self.s) cb(self.l,self.t,self.w,self.h,self.s)
_ = self.disableMaterial or self:drawMaterial( self.l,self.t,self.w,self.h,self.s) _ = self.disableMaterial or self:drawMaterial( self.l,self.t,self.w,self.h,self.s)
self:drawShadows( self.l,self.t,self.w,self.h,self.s) self:drawShadows( self.l,self.t,self.w,self.h,self.s)
_ = self.disableGlow or self:drawGlow( self.l,self.t,self.w,self.h,self.s) _ = self.disableGlow or self:drawGlow( self.l,self.t,self.w,self.h,self.s)
@ -110,7 +111,7 @@ function light_world:drawShadows(l,t,w,h,s)
love.graphics.setCanvas( self.normalMap ) love.graphics.setCanvas( self.normalMap )
love.graphics.clear() love.graphics.clear()
love.graphics.setCanvas() love.graphics.setCanvas()
util.drawto(self.normalMap, l, t, s, function() util.drawto(self.normalMap, l, t, s, false, function()
for i = 1, #self.bodies do for i = 1, #self.bodies do
if self.bodies[i]:isVisible() then if self.bodies[i]:isVisible() then
self.bodies[i]:drawNormal() self.bodies[i]:drawNormal()
@ -131,7 +132,8 @@ function light_world:drawShadows(l,t,w,h,s)
love.graphics.setCanvas( self.shadowMap ) love.graphics.setCanvas( self.shadowMap )
love.graphics.clear() love.graphics.clear()
love.graphics.setCanvas() love.graphics.setCanvas()
util.drawto(self.shadowMap, l, t, s, function()
util.drawto(self.shadowMap, l, t, s, true, function()
--I dont know if it uses both or just calls both --I dont know if it uses both or just calls both
love.graphics.stencil(function() love.graphics.stencil(function()
local angle = light.direction - (light.angle / 2.0) local angle = light.direction - (light.angle / 2.0)
@ -154,9 +156,10 @@ function light_world:drawShadows(l,t,w,h,s)
end end
end end
end) end)
-- draw scene for this light using normals and shadowmap -- 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('lightColor', {light.red, light.green, light.blue})
self.shadowShader:send("lightPosition", {(light.x + l/s) * 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})
self.shadowShader:send('lightRange',light.range * s) self.shadowShader:send('lightRange',light.range * s)
self.shadowShader:send("lightSmooth", light.smooth) self.shadowShader:send("lightSmooth", light.smooth)
self.shadowShader:send("lightGlow", {1.0 - light.glowSize, light.glowStrength}) self.shadowShader:send("lightGlow", {1.0 - light.glowSize, light.glowStrength})
@ -165,14 +168,16 @@ function light_world:drawShadows(l,t,w,h,s)
shader = self.shadowShader, shader = self.shadowShader,
stencil = function() stencil = function()
local angle = light.direction - (light.angle / 2.0) local angle = light.direction - (light.angle / 2.0)
love.graphics.arc("fill", (light.x + l/s) * s, (light.y + t/s) * s, light.range, angle, angle + light.angle) love.graphics.arc(
"fill", (light.x + l/s) * s, (light.y + t/s) * s, light.range, angle, angle + light.angle
)
end end
}) })
end end
end end
-- add in ambient color -- add in ambient color
util.drawto(self.shadow_buffer, l, t, s, function() util.drawto(self.shadow_buffer, l, t, s, false, function()
love.graphics.setBlendMode("add") love.graphics.setBlendMode("add")
love.graphics.setColor({self.ambient[1], self.ambient[2], self.ambient[3]}) love.graphics.setColor({self.ambient[1], self.ambient[2], self.ambient[3]})
love.graphics.rectangle("fill", -l/s, -t/s, w/s,h/s) love.graphics.rectangle("fill", -l/s, -t/s, w/s,h/s)
@ -209,7 +214,7 @@ function light_world:drawGlow(l,t,w,h,s)
love.graphics.setCanvas( self.glowMap ) love.graphics.setCanvas( self.glowMap )
love.graphics.clear() love.graphics.clear()
love.graphics.setCanvas() love.graphics.setCanvas()
util.drawto(self.glowMap, l, t, s, function() util.drawto(self.glowMap, l, t, s, false, function()
for i = 1, #self.bodies do for i = 1, #self.bodies do
if self.bodies[i]:isVisible() and self.bodies[i].glowStrength > 0.0 then if self.bodies[i]:isVisible() and self.bodies[i].glowStrength > 0.0 then
has_glow = true has_glow = true
@ -229,7 +234,7 @@ function light_world:drawRefraction(l,t,w,h,s)
love.graphics.setCanvas( self.refractionMap ) love.graphics.setCanvas( self.refractionMap )
love.graphics.clear() love.graphics.clear()
love.graphics.setCanvas() love.graphics.setCanvas()
util.drawto(self.refractionMap, l, t, s, function() util.drawto(self.refractionMap, l, t, s, false, function()
for i = 1, #self.bodies do for i = 1, #self.bodies do
if self.bodies[i]:isVisible() then if self.bodies[i]:isVisible() then
self.bodies[i]:drawRefraction() self.bodies[i]:drawRefraction()
@ -248,7 +253,7 @@ function light_world:drawReflection(l,t,w,h,s)
love.graphics.setCanvas( self.reflectionMap ) love.graphics.setCanvas( self.reflectionMap )
love.graphics.clear() love.graphics.clear()
love.graphics.setCanvas() love.graphics.setCanvas()
util.drawto(self.reflectionMap, l, t, s, function() util.drawto(self.reflectionMap, l, t, s, false, function()
for i = 1, #self.bodies do for i = 1, #self.bodies do
if self.bodies[i]:isVisible() then if self.bodies[i]:isVisible() then
self.bodies[i]:drawReflection() self.bodies[i]:drawReflection()
@ -280,7 +285,10 @@ end
function light_world:setScale(s) self.s = s end function light_world:setScale(s) self.s = s end
function light_world:clearLights() self.lights = {} end function light_world:clearLights() self.lights = {} end
function light_world:clearBodies() self.bodies = {} end function light_world:clearBodies() self.bodies = {} end
function light_world:setAmbientColor(red, green, blue) self.ambient = {red, green, blue} end function light_world:setAmbientColor(red, green, blue)
self.ambient = {red, green, blue}
for i, v in ipairs(self.ambient) do if v > 1 then self.ambient[i] = v / 255 end end
end
function light_world:setShadowBlur(blur) self.shadowBlur = blur end function light_world:setShadowBlur(blur) self.shadowBlur = blur end
function light_world:setGlowStrength(strength) self.glowBlur = strength end function light_world:setGlowStrength(strength) self.glowBlur = strength end
function light_world:setRefractionStrength(strength) self.refractionStrength = strength end function light_world:setRefractionStrength(strength) self.refractionStrength = strength end

View File

@ -5,15 +5,19 @@ local light = {}
light.__index = light light.__index = light
local function new(x, y, r, g, b, range) local function new(x, y, r, g, b, range)
if r and r > 1 then r = r / 255 end
if g and g > 1 then g = g / 255 end
if b and b > 1 then b = b / 255 end
local obj = { local obj = {
direction = 0, direction = 0,
angle = math.pi * 2.0, angle = math.pi * 2.0,
x = x or 0, x = x or 0,
y = y or 0, y = y or 0,
z = 1, z = 1,
red = r or 255, red = r or 1,
green = g or 255, green = g or 1,
blue = b or 255, blue = b or 1,
range = range or 300, range = range or 300,
smooth = 1.0, smooth = 1.0,
glowSize = 0.1, glowSize = 0.1,
@ -55,10 +59,14 @@ function light:getPosition()
end end
-- set color -- set color
function light:setColor(red, green, blue) function light:setColor(r, g, b)
self.red = red if r > 1 then r = r / 255 end
self.green = green if g > 1 then g = g / 255 end
self.blue = blue if b > 1 then b = b / 255 end
self.red = r
self.green = g
self.blue = b
end end
-- get range -- get range

View File

@ -1,7 +1,7 @@
local normal_map = {} local normal_map = {}
function normal_map.fromHeightMap(heightMap, strength) function normal_map.fromHeightMap(heightMap, strength)
local imgData = heightMap:getData() local imgData = normal_map.getImgData(heightMap)
local imgData2 = love.image.newImageData(heightMap:getWidth(), heightMap:getHeight()) local imgData2 = love.image.newImageData(heightMap:getWidth(), heightMap:getHeight())
local red, green, blue, alpha local red, green, blue, alpha
local x, y local x, y
@ -31,14 +31,14 @@ function normal_map.fromHeightMap(heightMap, strength)
y = i + m - 1 y = i + m - 1
end end
local red, green, blue, alpha = imgData:getPixel(x, y) local r, _g, _b, _a = imgData:getPixel(x, y)
matrix[l][m] = red matrix[l][m] = r
end end
end end
red = (255 + ((matrix[1][2] - matrix[2][2]) + (matrix[2][2] - matrix[3][2])) * strength) / 2.0 red = (1 + ((matrix[1][2] - matrix[2][2]) + (matrix[2][2] - matrix[3][2])) * strength) / 2.0
green = (255 + ((matrix[2][2] - matrix[1][1]) + (matrix[2][3] - matrix[2][2])) * strength) / 2.0 green = (1 + ((matrix[2][2] - matrix[1][1]) + (matrix[2][3] - matrix[2][2])) * strength) / 2.0
blue = 192 blue = 192/255
imgData2:setPixel(k, i, red, green, blue) imgData2:setPixel(k, i, red, green, blue)
end end
@ -48,20 +48,20 @@ function normal_map.fromHeightMap(heightMap, strength)
end end
function normal_map.generateFlat(img, mode) function normal_map.generateFlat(img, mode)
local imgData = img:getData() local imgData = normal_map.getImgData(img)
local imgNormalData = love.image.newImageData(img:getWidth(), img:getHeight()) local imgNormalData = love.image.newImageData(img:getWidth(), img:getHeight())
local color local color
if mode == "top" then if mode == "top" then
color = {127, 127, 255} color = {0.5, 0.5, 1}
elseif mode == "front" then elseif mode == "front" then
color = {127, 0, 127} color = {0.5, 0, 0.5}
elseif mode == "back" then elseif mode == "back" then
color = {127, 255, 127} color = {0.5, 1, 0.5}
elseif mode == "left" then elseif mode == "left" then
color = {31, 0, 223} color = {31/255, 0, 223/255}
elseif mode == "right" then elseif mode == "right" then
color = {223, 0, 127} color = {223/255, 0, 0.5}
end end
for i = 0, img:getHeight() - 1 do for i = 0, img:getHeight() - 1 do
@ -78,7 +78,7 @@ function normal_map.generateGradient(img, horizontalGradient, verticalGradient)
horizontalGradient = horizontalGradient or "gradient" horizontalGradient = horizontalGradient or "gradient"
verticalGradient = verticalGradient or horizontalGradient verticalGradient = verticalGradient or horizontalGradient
local imgData = img:getData() local imgData = normal_map.getImgData(img)
local imgWidth, imgHeight = img:getWidth(), img:getHeight() local imgWidth, imgHeight = img:getWidth(), img:getHeight()
local imgNormalData = love.image.newImageData(imgWidth, imgHeight) local imgNormalData = love.image.newImageData(imgWidth, imgHeight)
local dx = 255.0 / imgWidth local dx = 255.0 / imgWidth
@ -94,23 +94,23 @@ function normal_map.generateGradient(img, horizontalGradient, verticalGradient)
if horizontalGradient == "gradient" then if horizontalGradient == "gradient" then
nx = i * dx nx = i * dx
elseif horizontalGradient == "inverse" then elseif horizontalGradient == "inverse" then
nx = 255 - i * dx nx = 1 - i * dx
else else
nx = 127 nx = 0.5
end end
if verticalGradient == "gradient" then if verticalGradient == "gradient" then
ny = 127 - k * dy * 0.5 ny = 0.5 - k * dy * 0.5
nz = 255 - k * dy * 0.5 nz = 1 - k * dy * 0.5
elseif verticalGradient == "inverse" then elseif verticalGradient == "inverse" then
ny = 127 + k * dy * 0.5 ny = 0.5 + k * dy * 0.5
nz = 127 - k * dy * 0.25 nz = 0.5 - k * dy * 0.25
else else
ny = 255 ny = 1
nz = 127 nz = 0.5
end end
imgNormalData:setPixel(i, k, nx, ny, nz, 255) imgNormalData:setPixel(i, k, nx, ny, nz, 1)
end end
end end
end end
@ -118,4 +118,10 @@ function normal_map.generateGradient(img, horizontalGradient, verticalGradient)
return love.graphics.newImage(imgNormalData) return love.graphics.newImage(imgNormalData)
end end
function normal_map.getImgData(img)
local canvas = love.graphics.newCanvas(img:getWidth(), img:getHeight())
canvas:renderTo(function() love.graphics.draw(img, 0, 0) end)
return canvas:newImageData()
end
return normal_map return normal_map

View File

@ -27,12 +27,12 @@ local util = require(_PACKAGE..'/util')
local post_shader = {} local post_shader = {}
post_shader.__index = post_shader post_shader.__index = post_shader
local files = love.filesystem.getDirectoryItems(_PACKAGE.."/shaders/postshaders") local files = love.filesystem.getDirectoryItems(_PACKAGE .. "/shaders/postshaders")
local shaders = {} local shaders = {}
for i,v in ipairs(files) do for i,v in ipairs(files) do
local name = _PACKAGE.."/shaders/postshaders".."/"..v local name = _PACKAGE.."/shaders/postshaders".."/"..v
if love.filesystem.isFile(name) then if love.filesystem.getInfo(name).type == "file" and string.sub(v, 1, 1) ~= '.' then
local str = love.filesystem.read(name) local str = love.filesystem.read(name)
local effect = util.loadShader(name) local effect = util.loadShader(name)
local defs = {} local defs = {}
@ -94,7 +94,9 @@ function post_shader:drawBloom(canvas, args)
util.process(self.back_buffer, {shader = shaders['blurh'][1]}) util.process(self.back_buffer, {shader = shaders['blurh'][1]})
util.process(self.back_buffer, {shader = shaders['contrast'][1]}) util.process(self.back_buffer, {shader = shaders['contrast'][1]})
util.process(canvas, {shader = shaders['contrast'][1]}) util.process(canvas, {shader = shaders['contrast'][1]})
util.drawCanvasToCanvas(self.back_buffer, canvas, {blendmode = "add", color = {255, 255, 255, (args[2] or 0.25) * 255}}) util.drawCanvasToCanvas(self.back_buffer, canvas, {
blendmode = "add", color = {1, 1, 1, (args[2] or 0.25)}
})
end end
function post_shader:drawBlur(canvas, args) function post_shader:drawBlur(canvas, args)
@ -151,7 +153,7 @@ function post_shader:drawShader(shaderName, canvas, args)
end end
function process_tint(r, g, b) function process_tint(r, g, b)
return (r and r/255.0 or 1.0), (g and g/255.0 or 1.0), (b and b/255.0 or 1.0) return (r or 1.0), (g or 1.0), (b or 1.0)
end end
function process_palette(palette) function process_palette(palette)

View File

@ -21,6 +21,7 @@
// 0.5 = the spot stays inside the original pixel // 0.5 = the spot stays inside the original pixel
// 1.0 = the spot bleeds up to the center of next pixel // 1.0 = the spot bleeds up to the center of next pixel
#define PHOSPHOR_WIDTH 0.9 #define PHOSPHOR_WIDTH 0.9
#define PHOSPHOR_HEIGHT 0.65 #define PHOSPHOR_HEIGHT 0.65
@ -61,6 +62,7 @@ vec4 A_IN = vec4( 12.0/(InputGamma+1.0)-3.0 );
vec4 B_IN = vec4(1.0) - A_IN; vec4 B_IN = vec4(1.0) - A_IN;
vec4 A_OUT = vec4(6.0 - 15.0 * OutputGamma / 2.0 / (OutputGamma+1.0)); vec4 A_OUT = vec4(6.0 - 15.0 * OutputGamma / 2.0 / (OutputGamma+1.0));
vec4 B_OUT = vec4(1.0) - A_OUT; vec4 B_OUT = vec4(1.0) - A_OUT;
#define GAMMA_IN(color) ( (A_IN + B_IN * color) * color * color ) #define GAMMA_IN(color) ( (A_IN + B_IN * color) * color * color )
#define GAMMA_OUT(color) ( A_OUT * sqrt(color) + B_OUT * sqrt( sqrt(color) ) ) #define GAMMA_OUT(color) ( A_OUT * sqrt(color) + B_OUT * sqrt( sqrt(color) ) )
@ -76,25 +78,26 @@ vec4 B_IN = vec4(1.0) - A_IN;
#endif #endif
#ifdef DEBUG #ifdef DEBUG
vec4 grid_color( vec2 coords ) vec4 grid_color(Image tex, vec2 coords )
{ {
vec2 snes = floor( coords * love_ScreenSize ); vec2 snes = floor( coords * love_ScreenSize.xy );
if ( (mod(snes.x, 3.0) == 0.0) && (mod(snes.y, 3.0) == 0.0) ) if ( (mod(snes.x, 3.0) == 0.0) && (mod(snes.y, 3.0) == 0.0) ) {
return texture2D(_tex0_, coords); return texture2D(tex, coords);
else } else {
return vec4(0.0); return vec4(0.0);
}
} }
#define TEX2D(coords) GAMMA_IN( grid_color( coords ) ) #define TEX2D(tex, coords) GAMMA_IN( grid_color(tex, coords) )
#else // DEBUG #else // DEBUG
#define TEX2D(coords) GAMMA_IN( texture2D(_tex0_, coords) ) #define TEX2D(tex, coords) GAMMA_IN( texture2D(tex, coords) )
#endif // DEBUG #endif // DEBUG
vec2 onex = vec2( 1.0/love_ScreenSize.x, 0.0 ); vec2 onex = vec2( 1.0/love_ScreenSize.x, 0.0 );
vec2 oney = vec2( 0.0, 1.0/love_ScreenSize.y ); vec2 oney = vec2( 0.0, 1.0/love_ScreenSize.y );
vec4 effect(vec4 vcolor, Image texture, highp vec2 texCoord, vec2 pixel_coords) vec4 effect(vec4 vcolor, Image tex, highp vec2 texCoord, vec2 pixel_coords)
{ {
highp vec2 coords = (texCoord * love_ScreenSize.xy); highp vec2 coords = (texCoord * love_ScreenSize.xy);
highp vec2 pixel_start = floor(coords); highp vec2 pixel_start = floor(coords);
@ -121,9 +124,8 @@ vec4 effect(vec4 vcolor, Image texture, highp vec2 texCoord, vec2 pixel_coords)
if (vweight !=0.0 ) { if (vweight !=0.0 ) {
for ( i = -1.0; i<=1.0; i++ ) { for ( i = -1.0; i<=1.0; i++ ) {
pixel = TEX2D( pixel = TEX2D(
texture_coords tex,
+ i * onex texture_coords + i * onex + j * oney
+ j * oney
); );
/* Evaluate the distance (in x) from /* Evaluate the distance (in x) from

View File

@ -11,8 +11,10 @@ end
function util.drawCanvasToCanvas(canvas, other_canvas, options) function util.drawCanvasToCanvas(canvas, other_canvas, options)
options = options or {} options = options or {}
util.drawto(other_canvas, 0, 0, 1, function() util.drawto(other_canvas, 0, 0, 1, options['stencil'] or options['istencil'] and true or false, function()
if options["blendmode"] then if options["blendmode"] == 'multiply' then
love.graphics.setBlendMode(options["blendmode"], 'premultiplied')
elseif options["blendmode"] then
love.graphics.setBlendMode(options["blendmode"]) love.graphics.setBlendMode(options["blendmode"])
end end
if options["shader"] then if options["shader"] then
@ -29,7 +31,7 @@ function util.drawCanvasToCanvas(canvas, other_canvas, options)
if options["color"] then if options["color"] then
love.graphics.setColor(unpack(options["color"])) love.graphics.setColor(unpack(options["color"]))
else else
love.graphics.setColor(255,255,255) love.graphics.setColor(1,1,1)
end end
if love.graphics.getCanvas() ~= canvas then if love.graphics.getCanvas() ~= canvas then
love.graphics.draw(canvas,0,0) love.graphics.draw(canvas,0,0)
@ -47,11 +49,11 @@ function util.drawCanvasToCanvas(canvas, other_canvas, options)
end) end)
end end
function util.drawto(canvas, x, y, scale, cb) function util.drawto(canvas, x, y, scale, stencil, cb)
local last_buffer = love.graphics.getCanvas() local last_buffer = love.graphics.getCanvas()
love.graphics.push() love.graphics.push()
love.graphics.origin() love.graphics.origin()
love.graphics.setCanvas(canvas) love.graphics.setCanvas({ canvas, stencil = stencil })
love.graphics.translate(x, y) love.graphics.translate(x, y)
love.graphics.scale(scale) love.graphics.scale(scale)
cb() cb()
@ -96,4 +98,5 @@ function util.loadShader(name)
return effect return effect
end end
return util return util

View File

@ -27,7 +27,7 @@ function love.load()
local n = 0 local n = 0
for i, v in ipairs(files) do for i, v in ipairs(files) do
is_file = love.filesystem.isFile("examples/".. v ) is_file = (love.filesystem.getInfo("examples/".. v ).type == "file")
if is_file then if is_file then
n = n + 1 n = n + 1
table.insert(exf.available, v); table.insert(exf.available, v);
@ -63,10 +63,10 @@ function exf.draw()
lightWorld:draw(function() lightWorld:draw(function()
love.graphics.setBackgroundColor(0, 0, 0) love.graphics.setBackgroundColor(0, 0, 0)
love.graphics.setColor(48, 156, 225) love.graphics.setColor(48/255, 156/255, 225/255)
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()) love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
love.graphics.setColor(255, 255, 255, 191) love.graphics.setColor(1, 1, 1, 191/255)
love.graphics.setFont(exf.bigfont) love.graphics.setFont(exf.bigfont)
love.graphics.print("Examples:", 50, 50) love.graphics.print("Examples:", 50, 50)
@ -75,7 +75,7 @@ function exf.draw()
exf.list:draw() exf.list:draw()
love.graphics.setColor(255, 255, 255) love.graphics.setColor(1, 1, 1)
love.graphics.draw(exf.bigball, 800 - 128, 600 - 128, love.timer.getTime(), 1, 1, exf.bigball:getWidth() * 0.5, exf.bigball:getHeight() * 0.5) love.graphics.draw(exf.bigball, 800 - 128, 600 - 128, love.timer.getTime(), 1, 1, exf.bigball:getWidth() * 0.5, exf.bigball:getHeight() * 0.5)
end) end)
end end
@ -121,7 +121,7 @@ function exf.start(item, file)
local unused1, unused2, n = string.find(item, "(%s)%.lua") local unused1, unused2, n = string.find(item, "(%s)%.lua")
if exf.intable(exf.available, file) then if exf.intable(exf.available, file) then
if not love.filesystem.exists("examples/" .. file) then if not love.filesystem.getInfo("examples/" .. file) then
print("Could not load game .. " .. file) print("Could not load game .. " .. file)
else else
@ -158,7 +158,7 @@ end
function exf.clear() function exf.clear()
love.graphics.setBackgroundColor(0,0,0) love.graphics.setBackgroundColor(0,0,0)
love.graphics.setColor(255, 255, 255) love.graphics.setColor(1, 1, 1)
love.graphics.setLineWidth(1) love.graphics.setLineWidth(1)
love.graphics.setLineStyle("smooth") love.graphics.setLineStyle("smooth")
love.graphics.setBlendMode("alpha") love.graphics.setBlendMode("alpha")
@ -182,11 +182,11 @@ function exf.resume()
-- create light world -- create light world
lightWorld = LightWorld({ lightWorld = LightWorld({
ambient = {127, 127, 127} ambient = {127/255, 127/255, 127/255}
}) })
-- create light -- create light
lightMouse = lightWorld:newLight(0, 0, 255, 127, 63, 500) lightMouse = lightWorld:newLight(0, 0, 1, 127/255, 63/255, 500)
lightMouse:setSmooth(2) lightMouse:setSmooth(2)
-- create shadow bodys -- create shadow bodys
@ -337,7 +337,7 @@ function List:draw()
love.graphics.setLineStyle("rough") love.graphics.setLineStyle("rough")
love.graphics.setFont(self.font) love.graphics.setFont(self.font)
love.graphics.setColor(48, 156, 225) love.graphics.setColor(48/255, 156/255, 225 / 255)
local mx, my = love.mouse.getPosition() local mx, my = love.mouse.getPosition()
@ -357,17 +357,17 @@ function List:draw()
local hover = inside(mx, my, x, y, w, h) local hover = inside(mx, my, x, y, w, h)
if hover then if hover then
love.graphics.setColor(0, 0, 0, 127) love.graphics.setColor(0, 0, 0, 127/255)
else else
love.graphics.setColor(0, 0, 0, 63) love.graphics.setColor(0, 0, 0, 63/255)
end end
love.graphics.rectangle("fill", x+1, y+i+1, w-3, h) love.graphics.rectangle("fill", x+1, y+i+1, w-3, h)
if hover then if hover then
love.graphics.setColor(255, 255, 255) love.graphics.setColor(1, 1, 1, 1)
else else
love.graphics.setColor(255, 255, 255, 127) love.graphics.setColor(1, 1, 1, 127/255)
end end
local e_id = string.sub(self.items[i], 1, 5) local e_id = string.sub(self.items[i], 1, 5)
@ -385,15 +385,15 @@ function List:draw()
local hover = inside(mx, my, x, y, w, h) local hover = inside(mx, my, x, y, w, h)
if hover or self.bar_lock then if hover or self.bar_lock then
love.graphics.setColor(0, 0, 0, 127) love.graphics.setColor(0, 0, 0, 127/255)
else else
love.graphics.setColor(0, 0, 0, 63) love.graphics.setColor(0, 0, 0, 63/255)
end end
love.graphics.rectangle("fill", x, y, w, h) love.graphics.rectangle("fill", x, y, w, h)
end end
-- Border. -- Border.
love.graphics.setColor(0, 0, 0, 63) love.graphics.setColor(0, 0, 0, 63/255)
love.graphics.rectangle("line", self.x+self.width, self.y, self.bar_width, self.height) love.graphics.rectangle("line", self.x+self.width, self.y, self.bar_width, self.height)
love.graphics.rectangle("line", self.x, self.y, self.width, self.height) love.graphics.rectangle("line", self.x, self.y, self.width, self.height)
end end