Merge branch 'leokaplan-port0.10'

This commit is contained in:
Tim Anema 2016-04-26 09:22:42 -04:00
commit eedd980ff2
7 changed files with 58 additions and 38 deletions

View File

@ -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)

View File

@ -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")

View File

@ -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

View File

@ -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)
@ -107,8 +107,9 @@ end
-- draw normal shading
function light_world:drawShadows(l,t,w,h,s)
-- create normal map
self.normalMap:clear()
love.graphics.setCanvas( self.normalMap )
love.graphics.clear()
love.graphics.setCanvas()
util.drawto(self.normalMap, l, t, s, function()
for i = 1, #self.bodies do
if self.bodies[i]:isVisible() then
@ -120,19 +121,24 @@ 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.setStencilTest("greater",0)
love.graphics.stencil(function()
love.graphics.setShader(self.image_mask)
for k = 1, #self.bodies do
if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then
@ -141,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)
@ -149,12 +156,12 @@ 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})
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 +173,14 @@ 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"})
love.graphics.setStencilTest()
end
-- draw material
@ -198,7 +206,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 +220,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 +245,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

View File

@ -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

View File

@ -1,7 +1,11 @@
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)
util.drawCanvasToCanvas(canvas, canvas, options)
--TODO: now you cannot draw a canvas to itself
temp = love.graphics.newCanvas()
util.drawCanvasToCanvas(canvas, temp, options)
util.drawCanvasToCanvas(temp, canvas, options)
end
function util.drawCanvasToCanvas(canvas, other_canvas, options)
@ -15,28 +19,30 @@ 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"])
love.graphics.setStencilTest("greater",0)
end
if options["istencil"] then
love.graphics.setInvertedStencil(options["istencil"])
love.graphics.stencil(options["istencil"])
love.graphics.setStencilTest("equal", 0)
end
if options["color"] then
love.graphics.setColor(unpack(options["color"]))
else
love.graphics.setColor(255,255,255)
end
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
love.graphics.setStencil()
end
if options["istencil"] then
love.graphics.setInvertedStencil()
if options["stencil"] or options["istencil"] then
--love.graphics.setInvertedStencil()
love.graphics.setStencilTest()
end
end)
end

View File

@ -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