mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
initial port
This commit is contained in:
parent
1cd37aebff
commit
85d4fbbba7
4
conf.lua
4
conf.lua
@ -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.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.console = true -- Attach a console (boolean, Windows only)
|
||||||
|
|
||||||
t.window.title = "Untitled" -- The window title (string)
|
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.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.minheight = 1 -- Minimum window height if the window is resizable (number)
|
||||||
t.window.fullscreen = false -- Enable fullscreen (boolean)
|
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.vsync = false -- Enable vertical sync (boolean)
|
||||||
t.window.fsaa = 0 -- The number of samples to use with multi-sampled antialiasing (number)
|
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)
|
t.window.display = 1 -- Index of the monitor to show the window in (number)
|
||||||
|
@ -40,7 +40,7 @@ function love.load()
|
|||||||
love.graphics.setFont(font)
|
love.graphics.setFont(font)
|
||||||
|
|
||||||
-- set background
|
-- 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 = love.graphics.newImage("examples/gfx/floor.png")
|
||||||
imgFloor:setWrap("repeat", "repeat")
|
imgFloor:setWrap("repeat", "repeat")
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ local function new(id, type, ...)
|
|||||||
util.drawto(circle_canvas, 0, 0, 1, function()
|
util.drawto(circle_canvas, 0, 0, 1, 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:getImageData())
|
obj.img = love.graphics.newImage(circle_canvas:newImageData())
|
||||||
obj.imgWidth = obj.img:getWidth()
|
obj.imgWidth = obj.img:getWidth()
|
||||||
obj.imgHeight = obj.img:getHeight()
|
obj.imgHeight = obj.img:getHeight()
|
||||||
obj.ix = obj.imgWidth * 0.5
|
obj.ix = obj.imgWidth * 0.5
|
||||||
@ -347,7 +347,7 @@ function body:setPoints(...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not self.img then
|
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.imgWidth = self.img:getWidth()
|
||||||
self.imgHeight = self.img:getHeight()
|
self.imgHeight = self.img:getHeight()
|
||||||
self.ix = self.imgWidth * 0.5
|
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()},
|
{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()}
|
{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
|
else
|
||||||
self.normalMesh = nil
|
self.normalMesh = nil
|
||||||
end
|
end
|
||||||
|
37
lib/init.lua
37
lib/init.lua
@ -67,7 +67,7 @@ local function new(options)
|
|||||||
end
|
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.graphics.getWidth(), h or love.graphics.getHeight()
|
||||||
|
|
||||||
self.w, self.h = w, h
|
self.w, self.h = w, h
|
||||||
self.render_buffer = love.graphics.newCanvas(w, h)
|
self.render_buffer = love.graphics.newCanvas(w, h)
|
||||||
@ -108,8 +108,8 @@ end
|
|||||||
-- draw normal shading
|
-- draw normal shading
|
||||||
function light_world:drawShadows(l,t,w,h,s)
|
function light_world:drawShadows(l,t,w,h,s)
|
||||||
-- create normal map
|
-- create normal map
|
||||||
self.normalMap:clear()
|
|
||||||
util.drawto(self.normalMap, l, t, s, function()
|
util.drawto(self.normalMap, l, t, s, function()
|
||||||
|
love.graphics.clear()
|
||||||
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()
|
||||||
@ -120,20 +120,25 @@ function light_world:drawShadows(l,t,w,h,s)
|
|||||||
self.shadowShader:send('normalMap', self.normalMap)
|
self.shadowShader:send('normalMap', self.normalMap)
|
||||||
self.shadowShader:send("invert_normal", self.normalInvert == true)
|
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
|
for i = 1, #self.lights do
|
||||||
local light = self.lights[i]
|
local light = self.lights[i]
|
||||||
if light:isVisible() then
|
if light:isVisible() then
|
||||||
-- create shadow map for this light
|
-- 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()
|
util.drawto(self.shadowMap, l, t, s, 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.setStencil(function()
|
love.graphics.stencil(function()
|
||||||
local angle = light.direction - (light.angle / 2.0)
|
local angle = light.direction - (light.angle / 2.0)
|
||||||
love.graphics.arc("fill", light.x, light.y, light.range, angle, angle + light.angle)
|
love.graphics.arc("fill", light.x, light.y, light.range, angle, angle + light.angle)
|
||||||
end)
|
end)
|
||||||
love.graphics.setInvertedStencil(function()
|
love.graphics.stencil(function()
|
||||||
love.graphics.setShader(self.image_mask)
|
love.graphics.setShader(self.image_mask)
|
||||||
|
-- TODO:invert mask
|
||||||
for k = 1, #self.bodies do
|
for k = 1, #self.bodies do
|
||||||
if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then
|
if self.bodies[k]:inLightRange(light) and self.bodies[k]:isVisible() then
|
||||||
self.bodies[k]:drawStencil()
|
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("lightSmooth", light.smooth)
|
||||||
self.shadowShader:send("lightGlow", {1.0 - light.glowSize, light.glowStrength})
|
self.shadowShader:send("lightGlow", {1.0 - light.glowSize, light.glowStrength})
|
||||||
util.drawCanvasToCanvas(self.shadowMap, self.shadow_buffer, {
|
util.drawCanvasToCanvas(self.shadowMap, self.shadow_buffer, {
|
||||||
blendmode = 'additive',
|
blendmode = 'add',
|
||||||
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)
|
||||||
@ -166,13 +171,13 @@ function light_world:drawShadows(l,t,w,h,s)
|
|||||||
|
|
||||||
-- 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, function()
|
||||||
love.graphics.setBlendMode("additive")
|
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)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
self.post_shader:drawBlur(self.shadow_buffer, {self.shadowBlur})
|
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
|
end
|
||||||
|
|
||||||
-- draw material
|
-- draw material
|
||||||
@ -198,7 +203,9 @@ function light_world:drawGlow(l,t,w,h,s)
|
|||||||
|
|
||||||
local has_glow = false
|
local has_glow = false
|
||||||
-- create glow map
|
-- 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()
|
util.drawto(self.glowMap, l, t, s, 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
|
||||||
@ -210,13 +217,15 @@ function light_world:drawGlow(l,t,w,h,s)
|
|||||||
|
|
||||||
if has_glow then
|
if has_glow then
|
||||||
self.post_shader:drawBlur(self.glowMap, {self.glowBlur})
|
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
|
||||||
end
|
end
|
||||||
-- draw refraction
|
-- draw refraction
|
||||||
function light_world:drawRefraction(l,t,w,h,s)
|
function light_world:drawRefraction(l,t,w,h,s)
|
||||||
-- create refraction map
|
-- 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()
|
util.drawto(self.refractionMap, l, t, s, 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
|
||||||
@ -233,7 +242,9 @@ end
|
|||||||
-- draw reflection
|
-- draw reflection
|
||||||
function light_world:drawReflection(l,t,w,h,s)
|
function light_world:drawReflection(l,t,w,h,s)
|
||||||
-- create reflection map
|
-- 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()
|
util.drawto(self.reflectionMap, l, t, s, 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
|
||||||
|
@ -52,7 +52,7 @@ local function new()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function post_shader:refreshScreenSize(w, h)
|
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)
|
self.back_buffer = love.graphics.newCanvas(w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
16
lib/util.lua
16
lib/util.lua
@ -1,6 +1,8 @@
|
|||||||
local util = {}
|
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)
|
function util.process(canvas, options)
|
||||||
|
--TODO: now you cannot draw a canvas to itself
|
||||||
util.drawCanvasToCanvas(canvas, canvas, options)
|
util.drawCanvasToCanvas(canvas, canvas, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -15,17 +17,21 @@ function util.drawCanvasToCanvas(canvas, other_canvas, options)
|
|||||||
love.graphics.setShader(options["shader"])
|
love.graphics.setShader(options["shader"])
|
||||||
end
|
end
|
||||||
if options["stencil"] then
|
if options["stencil"] then
|
||||||
love.graphics.setStencil(options["stencil"])
|
love.graphics.stencil(options["stencil"])
|
||||||
end
|
end
|
||||||
if options["istencil"] then
|
if options["istencil"] then
|
||||||
love.graphics.setInvertedStencil(options["istencil"])
|
love.graphics.stencil(options["istencil"])
|
||||||
|
--TODO: invert map
|
||||||
end
|
end
|
||||||
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(255,255,255)
|
||||||
end
|
end
|
||||||
|
--TODO: not really sure if this is right
|
||||||
|
love.graphics.setCanvas()
|
||||||
love.graphics.draw(canvas,0,0)
|
love.graphics.draw(canvas,0,0)
|
||||||
|
love.graphics.setCanvas(canvas)
|
||||||
if options["blendmode"] then
|
if options["blendmode"] then
|
||||||
love.graphics.setBlendMode("alpha")
|
love.graphics.setBlendMode("alpha")
|
||||||
end
|
end
|
||||||
@ -33,10 +39,12 @@ function util.drawCanvasToCanvas(canvas, other_canvas, options)
|
|||||||
love.graphics.setShader()
|
love.graphics.setShader()
|
||||||
end
|
end
|
||||||
if options["stencil"] then
|
if options["stencil"] then
|
||||||
love.graphics.setStencil()
|
--TODO: check if commenting this is really ok
|
||||||
|
--love.graphics.stencil()
|
||||||
end
|
end
|
||||||
if options["istencil"] then
|
if options["istencil"] then
|
||||||
love.graphics.setInvertedStencil()
|
--TODO: check if commenting this is really ok
|
||||||
|
--love.graphics.setInvertedStencil()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
13
main.lua
13
main.lua
@ -5,7 +5,6 @@
|
|||||||
-- All examples in one application! Yaay!
|
-- All examples in one application! Yaay!
|
||||||
--
|
--
|
||||||
-- Updated by Dresenpai
|
-- Updated by Dresenpai
|
||||||
|
|
||||||
require "lib/postshader"
|
require "lib/postshader"
|
||||||
local LightWorld = require "lib"
|
local LightWorld = require "lib"
|
||||||
local ProFi = require 'examples.vendor.ProFi'
|
local ProFi = require 'examples.vendor.ProFi'
|
||||||
@ -17,8 +16,8 @@ exf.available = {}
|
|||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
exf.list = List:new()
|
exf.list = List:new()
|
||||||
exf.smallfont = love.graphics.newFont(love._vera_ttf,12)
|
exf.smallfont = love.graphics.newFont(12)
|
||||||
exf.bigfont = love.graphics.newFont(love._vera_ttf, 24)
|
exf.bigfont = love.graphics.newFont(24)
|
||||||
exf.list.font = exf.smallfont
|
exf.list.font = exf.smallfont
|
||||||
|
|
||||||
exf.bigball = love.graphics.newImage("examples/gfx/love-big-ball.png")
|
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.setBackgroundColor(0, 0, 0)
|
||||||
|
|
||||||
love.graphics.setColor(48, 156, 225)
|
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.setColor(255, 255, 255, 191)
|
||||||
love.graphics.setFont(exf.bigfont)
|
love.graphics.setFont(exf.bigfont)
|
||||||
@ -281,7 +280,7 @@ end
|
|||||||
|
|
||||||
function List:mousepressed(mx, my, b)
|
function List:mousepressed(mx, my, b)
|
||||||
if self:hasBar() then
|
if self:hasBar() then
|
||||||
if b == "l" then
|
if b == 1 then
|
||||||
local x, y, w, h = self:getBarRect()
|
local x, y, w, h = self:getBarRect()
|
||||||
if inside(mx, my, x, y, w, h) then
|
if inside(mx, my, x, y, w, h) then
|
||||||
self.bar_lock = { x = mx, y = my }
|
self.bar_lock = { x = mx, y = my }
|
||||||
@ -304,7 +303,7 @@ function List:mousepressed(mx, my, b)
|
|||||||
end
|
end
|
||||||
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 tx, ty = mx-self.x, my + self:getOffset() - self.y
|
||||||
local index = math.floor((ty/self.sum_item_height)*self.items.n)
|
local index = math.floor((ty/self.sum_item_height)*self.items.n)
|
||||||
local i = self.items[index+1]
|
local i = self.items[index+1]
|
||||||
@ -317,7 +316,7 @@ end
|
|||||||
|
|
||||||
function List:mousereleased(x, y, b)
|
function List:mousereleased(x, y, b)
|
||||||
if self:hasBar() then
|
if self:hasBar() then
|
||||||
if b == "l" then
|
if b == 1 then
|
||||||
self.bar_lock = nil
|
self.bar_lock = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user