no longer need two callback for drawing just one, which is nice

This commit is contained in:
Tim Anema 2014-11-30 15:24:58 -05:00
parent 66dd1b65f8
commit 5351b91168
6 changed files with 102 additions and 121 deletions

View File

@ -235,10 +235,57 @@ end
function love.draw()
-- set shader buffer
lightWorld:setTranslation(offsetX,offsetY, scale)
love.graphics.push()
love.graphics.translate(offsetX, offsetY)
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.draw(imgLight, mx - 5, (my - 5) - (16.0 + (math.sin(lightDirection) + 1.0) * 64.0))
@ -334,56 +381,6 @@ function love.draw()
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)
if c == "m" then
-- add light

View File

@ -54,22 +54,17 @@ function love.update(dt)
end
function love.draw()
lightWorld:setTranslation(x,y,scale)
love.graphics.push()
love.graphics.translate(x, y)
love.graphics.scale(scale)
lightWorld:draw(x,y,scale)
love.graphics.pop()
end
function drawBackground(l,t,w,h)
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)
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)
love.graphics.pop()
end

View File

@ -130,10 +130,20 @@ function love.mousepressed(x, y, c)
end
function love.draw()
lightWorld:setTranslation(x, y, scale)
love.graphics.push()
love.graphics.translate(x, y)
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.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("light z: " .. lightMouse.z, 0, 50)
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

View File

@ -43,17 +43,11 @@ function love.update(dt)
end
function love.draw()
lightWorld:draw()
end
function drawBackground(l,t,w,h)
lightWorld:draw(function(l, t, w, h, s)
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)
end

View File

@ -44,6 +44,8 @@ function light_world:init(options)
self.body = {}
self.post_shader = PostShader()
self.l, self.t, self.s = 0, 0, 1
self.ambient = {0, 0, 0}
self.refractionStrength = 8.0
@ -68,6 +70,7 @@ end
function light_world:refreshScreenSize(w, h)
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.normal = 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)
end
function light_world:draw(l,t,s)
l,t,s = (l or 0), (t or 0), s or 1
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
util.drawto(self.render_buffer, l, t, s, function()
self.drawBackground( l,t,w,h,s)
self.drawForeground( l,t,w,h,s)
self:drawMaterial( l,t,w,h,s)
self:drawNormalShading( l,t,w,h,s)
self:drawGlow( l,t,w,h,s)
self:drawRefraction( l,t,w,h,s)
self:drawReflection( l,t,w,h,s)
function light_world:setTranslation(l, t, s)
self.l, self.t, self.s = l, t, s
end
function light_world:draw(cb)
util.drawto(self.render_buffer, self.l, self.t, self.s, function()
cb( self.l,self.t,self.w,self.h,self.s)
self:drawMaterial( self.l,self.t,self.w,self.h,self.s)
self:drawNormalShading( self.l,self.t,self.w,self.h,self.s)
self:drawGlow( self.l,self.t,self.w,self.h,self.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)
self.post_shader:drawWith(self.render_buffer, l, t, s)
self.post_shader:drawWith(self.render_buffer, self.l, self.t, self.s)
end
-- draw normal shading

View File

@ -60,10 +60,7 @@ function exf.update(dt)
end
function exf.draw()
lightWorld:draw()
end
function exf.drawBackground()
lightWorld:draw(function()
love.graphics.setBackgroundColor(0, 0, 0)
love.graphics.setColor(48, 156, 225)
@ -77,11 +74,10 @@ function exf.drawBackground()
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()
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)