mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
no longer need two callback for drawing just one, which is nice
This commit is contained in:
parent
66dd1b65f8
commit
5351b91168
@ -235,10 +235,57 @@ end
|
|||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
-- set shader buffer
|
-- set shader buffer
|
||||||
|
lightWorld:setTranslation(offsetX,offsetY, scale)
|
||||||
love.graphics.push()
|
love.graphics.push()
|
||||||
love.graphics.translate(offsetX, offsetY)
|
love.graphics.translate(offsetX, offsetY)
|
||||||
love.graphics.scale(scale)
|
love.graphics.scale(scale)
|
||||||
lightWorld:draw(offsetX,offsetY, scale)
|
lightWorld:draw(function(l, t, w, h, s)
|
||||||
|
love.graphics.setBlendMode("alpha")
|
||||||
|
if normalOn then
|
||||||
|
love.graphics.setColor(127, 127, 255)
|
||||||
|
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||||
|
else
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
if textureOn then
|
||||||
|
love.graphics.draw(imgFloor, quadScreen, 0,0)
|
||||||
|
else
|
||||||
|
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = 1, phyCnt do
|
||||||
|
if phyLight[i]:getType() == "refraction" then
|
||||||
|
if not normalOn then
|
||||||
|
love.graphics.setBlendMode("alpha")
|
||||||
|
love.graphics.setColor(255, 255, 255, 191)
|
||||||
|
love.graphics.draw(water, phyLight[i].x - phyLight[i].ox, phyLight[i].y - phyLight[i].oy)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.setBlendMode("alpha")
|
||||||
|
for i = 1, phyCnt do
|
||||||
|
if phyLight[i]:getType() == "polygon" then
|
||||||
|
math.randomseed(i)
|
||||||
|
love.graphics.setColor(math.random(0, 255), math.random(0, 255), math.random(0, 255))
|
||||||
|
love.graphics.polygon("fill", phyLight[i]:getPoints())
|
||||||
|
elseif phyLight[i]:getType() == "circle" then
|
||||||
|
math.randomseed(i)
|
||||||
|
love.graphics.setColor(math.random(0, 255), math.random(0, 255), math.random(0, 255))
|
||||||
|
local cx, cy = phyLight[i]:getPosition()
|
||||||
|
love.graphics.circle("fill", cx, cy, phyLight[i]:getRadius())
|
||||||
|
elseif phyLight[i]:getType() == "image" then
|
||||||
|
if normalOn and phyLight[i].normal then
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.draw(phyLight[i].normal, phyLight[i].x - phyLight[i].nx, phyLight[i].y - phyLight[i].ny)
|
||||||
|
elseif not phyLight[i].material then
|
||||||
|
math.randomseed(i)
|
||||||
|
love.graphics.setColor(math.random(127, 255), math.random(127, 255), math.random(127, 255))
|
||||||
|
love.graphics.draw(phyLight[i].img, phyLight[i].x - phyLight[i].ix, phyLight[i].y - phyLight[i].iy)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
|
|
||||||
love.graphics.draw(imgLight, mx - 5, (my - 5) - (16.0 + (math.sin(lightDirection) + 1.0) * 64.0))
|
love.graphics.draw(imgLight, mx - 5, (my - 5) - (16.0 + (math.sin(lightDirection) + 1.0) * 64.0))
|
||||||
@ -334,56 +381,6 @@ function love.draw()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawBackground(l,t,w,h)
|
|
||||||
love.graphics.setBlendMode("alpha")
|
|
||||||
if normalOn then
|
|
||||||
love.graphics.setColor(127, 127, 255)
|
|
||||||
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
|
||||||
else
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
|
||||||
if textureOn then
|
|
||||||
love.graphics.draw(imgFloor, quadScreen, 0,0)
|
|
||||||
else
|
|
||||||
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = 1, phyCnt do
|
|
||||||
if phyLight[i]:getType() == "refraction" then
|
|
||||||
if not normalOn then
|
|
||||||
love.graphics.setBlendMode("alpha")
|
|
||||||
love.graphics.setColor(255, 255, 255, 191)
|
|
||||||
love.graphics.draw(water, phyLight[i].x - phyLight[i].ox, phyLight[i].y - phyLight[i].oy)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function drawForeground(l,t,w,h)
|
|
||||||
love.graphics.setBlendMode("alpha")
|
|
||||||
for i = 1, phyCnt do
|
|
||||||
if phyLight[i]:getType() == "polygon" then
|
|
||||||
math.randomseed(i)
|
|
||||||
love.graphics.setColor(math.random(0, 255), math.random(0, 255), math.random(0, 255))
|
|
||||||
love.graphics.polygon("fill", phyLight[i]:getPoints())
|
|
||||||
elseif phyLight[i]:getType() == "circle" then
|
|
||||||
math.randomseed(i)
|
|
||||||
love.graphics.setColor(math.random(0, 255), math.random(0, 255), math.random(0, 255))
|
|
||||||
local cx, cy = phyLight[i]:getPosition()
|
|
||||||
love.graphics.circle("fill", cx, cy, phyLight[i]:getRadius())
|
|
||||||
elseif phyLight[i]:getType() == "image" then
|
|
||||||
if normalOn and phyLight[i].normal then
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
|
||||||
love.graphics.draw(phyLight[i].normal, phyLight[i].x - phyLight[i].nx, phyLight[i].y - phyLight[i].ny)
|
|
||||||
elseif not phyLight[i].material then
|
|
||||||
math.randomseed(i)
|
|
||||||
love.graphics.setColor(math.random(127, 255), math.random(127, 255), math.random(127, 255))
|
|
||||||
love.graphics.draw(phyLight[i].img, phyLight[i].x - phyLight[i].ix, phyLight[i].y - phyLight[i].iy)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.mousepressed(x, y, c)
|
function love.mousepressed(x, y, c)
|
||||||
if c == "m" then
|
if c == "m" then
|
||||||
-- add light
|
-- add light
|
||||||
|
@ -54,22 +54,17 @@ function love.update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
|
lightWorld:setTranslation(x,y,scale)
|
||||||
love.graphics.push()
|
love.graphics.push()
|
||||||
love.graphics.translate(x, y)
|
love.graphics.translate(x, y)
|
||||||
love.graphics.scale(scale)
|
love.graphics.scale(scale)
|
||||||
lightWorld:draw(x,y,scale)
|
lightWorld:draw(function(l, t, w, h, s)
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.rectangle("fill", -l/scale, -t/scale, w/scale, h/scale)
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
|
||||||
|
love.graphics.draw(image, w/2-(image:getWidth()/2), h/2-(image:getHeight()/2))
|
||||||
|
end)
|
||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawBackground(l,t,w,h)
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
|
||||||
love.graphics.rectangle("fill", -l/scale, -t/scale, w/scale, h/scale)
|
|
||||||
end
|
|
||||||
|
|
||||||
function drawForeground(l,t,w,h)
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
|
||||||
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
|
|
||||||
love.graphics.draw(image, w/2-(image:getWidth()/2), h/2-(image:getHeight()/2))
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,10 +130,20 @@ function love.mousepressed(x, y, c)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
|
lightWorld:setTranslation(x, y, scale)
|
||||||
love.graphics.push()
|
love.graphics.push()
|
||||||
love.graphics.translate(x, y)
|
love.graphics.translate(x, y)
|
||||||
love.graphics.scale(scale)
|
love.graphics.scale(scale)
|
||||||
lightWorld:draw(x,y,scale)
|
lightWorld:draw(function()
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.rectangle("fill", -x/scale, -y/scale, love.graphics.getWidth()/scale, love.graphics.getHeight()/scale)
|
||||||
|
love.graphics.setColor(63, 255, 127)
|
||||||
|
local cx, cy = circleTest:getPosition()
|
||||||
|
love.graphics.circle("fill", cx, cy, circleTest:getRadius())
|
||||||
|
love.graphics.polygon("fill", rectangleTest:getPoints())
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.draw(image, 64 - image:getWidth() * 0.5, 64 - image:getHeight() * 0.5)
|
||||||
|
end)
|
||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
|
|
||||||
love.graphics.setBlendMode("alpha")
|
love.graphics.setBlendMode("alpha")
|
||||||
@ -143,18 +153,3 @@ function love.draw()
|
|||||||
love.graphics.print("To toggle postshaders, use 0-9 and q->y, to scale use - and =, and to translate use arrows")
|
love.graphics.print("To toggle postshaders, use 0-9 and q->y, to scale use - and =, and to translate use arrows")
|
||||||
love.graphics.print("light z: " .. lightMouse.z, 0, 50)
|
love.graphics.print("light z: " .. lightMouse.z, 0, 50)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawBackground(l,t,w,h)
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
|
||||||
love.graphics.rectangle("fill", -l/scale, -t/scale, w/scale, h/scale)
|
|
||||||
end
|
|
||||||
|
|
||||||
function drawForeground(l,t,w,h)
|
|
||||||
love.graphics.setColor(63, 255, 127)
|
|
||||||
local cx, cy = circleTest:getPosition()
|
|
||||||
love.graphics.circle("fill", cx, cy, circleTest:getRadius())
|
|
||||||
love.graphics.polygon("fill", rectangleTest:getPoints())
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
|
||||||
love.graphics.draw(image, 64 - image:getWidth() * 0.5, 64 - image:getHeight() * 0.5)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
@ -43,17 +43,11 @@ function love.update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
lightWorld:draw()
|
lightWorld:draw(function(l, t, w, h, s)
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.rectangle("fill", l, t, w, h)
|
||||||
|
love.graphics.setColor(0, 255, 0)
|
||||||
|
love.graphics.circle('fill', 150, 150, 50)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawBackground(l,t,w,h)
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
|
||||||
love.graphics.rectangle("fill", l, t, w, h)
|
|
||||||
end
|
|
||||||
|
|
||||||
function drawForeground(l,t,w,h)
|
|
||||||
love.graphics.setColor(0, 255, 0)
|
|
||||||
love.graphics.circle('fill', 150, 150, 50)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
28
lib/init.lua
28
lib/init.lua
@ -44,6 +44,8 @@ function light_world:init(options)
|
|||||||
self.body = {}
|
self.body = {}
|
||||||
self.post_shader = PostShader()
|
self.post_shader = PostShader()
|
||||||
|
|
||||||
|
self.l, self.t, self.s = 0, 0, 1
|
||||||
|
|
||||||
self.ambient = {0, 0, 0}
|
self.ambient = {0, 0, 0}
|
||||||
|
|
||||||
self.refractionStrength = 8.0
|
self.refractionStrength = 8.0
|
||||||
@ -68,6 +70,7 @@ end
|
|||||||
function light_world:refreshScreenSize(w, h)
|
function light_world:refreshScreenSize(w, h)
|
||||||
w, h = w or love.window.getWidth(), h or love.window.getHeight()
|
w, h = w or love.window.getWidth(), h or love.window.getHeight()
|
||||||
|
|
||||||
|
self.w, self.h = w, h
|
||||||
self.render_buffer = love.graphics.newCanvas(w, h)
|
self.render_buffer = love.graphics.newCanvas(w, h)
|
||||||
self.normal = love.graphics.newCanvas(w, h)
|
self.normal = love.graphics.newCanvas(w, h)
|
||||||
self.normal2 = love.graphics.newCanvas(w, h)
|
self.normal2 = love.graphics.newCanvas(w, h)
|
||||||
@ -92,19 +95,20 @@ function light_world:refreshScreenSize(w, h)
|
|||||||
self.post_shader:refreshScreenSize(w, h)
|
self.post_shader:refreshScreenSize(w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function light_world:draw(l,t,s)
|
function light_world:setTranslation(l, t, s)
|
||||||
l,t,s = (l or 0), (t or 0), s or 1
|
self.l, self.t, self.s = l, t, s
|
||||||
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
|
end
|
||||||
util.drawto(self.render_buffer, l, t, s, function()
|
|
||||||
self.drawBackground( l,t,w,h,s)
|
function light_world:draw(cb)
|
||||||
self.drawForeground( l,t,w,h,s)
|
util.drawto(self.render_buffer, self.l, self.t, self.s, function()
|
||||||
self:drawMaterial( l,t,w,h,s)
|
cb( self.l,self.t,self.w,self.h,self.s)
|
||||||
self:drawNormalShading( l,t,w,h,s)
|
self:drawMaterial( self.l,self.t,self.w,self.h,self.s)
|
||||||
self:drawGlow( l,t,w,h,s)
|
self:drawNormalShading( self.l,self.t,self.w,self.h,self.s)
|
||||||
self:drawRefraction( l,t,w,h,s)
|
self:drawGlow( self.l,self.t,self.w,self.h,self.s)
|
||||||
self:drawReflection( l,t,w,h,s)
|
self:drawRefraction( self.l,self.t,self.w,self.h,self.s)
|
||||||
|
self:drawReflection( self.l,self.t,self.w,self.h,self.s)
|
||||||
end)
|
end)
|
||||||
self.post_shader:drawWith(self.render_buffer, l, t, s)
|
self.post_shader:drawWith(self.render_buffer, self.l, self.t, self.s)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- draw normal shading
|
-- draw normal shading
|
||||||
|
30
main.lua
30
main.lua
@ -60,28 +60,24 @@ function exf.update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function exf.draw()
|
function exf.draw()
|
||||||
lightWorld:draw()
|
lightWorld:draw(function()
|
||||||
end
|
love.graphics.setBackgroundColor(0, 0, 0)
|
||||||
|
|
||||||
function exf.drawBackground()
|
love.graphics.setColor(48, 156, 225)
|
||||||
love.graphics.setBackgroundColor(0, 0, 0)
|
love.graphics.rectangle("fill", 0, 0, love.window.getWidth(), love.window.getHeight())
|
||||||
|
|
||||||
love.graphics.setColor(48, 156, 225)
|
love.graphics.setColor(255, 255, 255, 191)
|
||||||
love.graphics.rectangle("fill", 0, 0, love.window.getWidth(), love.window.getHeight())
|
love.graphics.setFont(exf.bigfont)
|
||||||
|
love.graphics.print("Examples:", 50, 50)
|
||||||
|
|
||||||
love.graphics.setColor(255, 255, 255, 191)
|
love.graphics.setFont(exf.smallfont)
|
||||||
love.graphics.setFont(exf.bigfont)
|
love.graphics.print("Browse and click on the example you \nwant to run. To return the the example \nselection screen, press escape.", 500, 80)
|
||||||
love.graphics.print("Examples:", 50, 50)
|
|
||||||
|
|
||||||
love.graphics.setFont(exf.smallfont)
|
exf.list:draw()
|
||||||
love.graphics.print("Browse and click on the example you \nwant to run. To return the the example \nselection screen, press escape.", 500, 80)
|
|
||||||
|
|
||||||
exf.list:draw()
|
love.graphics.setColor(255, 255, 255)
|
||||||
end
|
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)
|
||||||
function exf.drawForeground()
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
|
||||||
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
|
||||||
|
|
||||||
function exf.keypressed(k)
|
function exf.keypressed(k)
|
||||||
|
Loading…
Reference in New Issue
Block a user