2014-10-27 18:43:58 +00:00
|
|
|
-- Example: Normal map Example
|
2014-10-27 19:24:28 +00:00
|
|
|
local LightWorld = require "lib"
|
2021-11-10 01:15:14 +00:00
|
|
|
local image, image_normal
|
|
|
|
local lightWorld, lightMouse
|
2014-10-27 18:43:58 +00:00
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function load()
|
2014-10-27 18:43:58 +00:00
|
|
|
-- load images
|
2021-11-20 01:14:08 +00:00
|
|
|
image = love.graphics.newImage("examples/img/normalMap/rock.png")
|
|
|
|
image_normal = love.graphics.newImage("examples/img/normalMap/normal.png")
|
2014-10-27 18:43:58 +00:00
|
|
|
-- create light world
|
2021-11-10 01:15:14 +00:00
|
|
|
lightWorld = LightWorld({ambient = {0.21,0.21,0.21}})
|
2014-10-27 18:43:58 +00:00
|
|
|
-- create light
|
|
|
|
lightMouse = lightWorld:newLight(0, 0, 160, 160, 160, 300)
|
2021-11-10 01:15:14 +00:00
|
|
|
lightMouse.normalInvert = true
|
2014-10-27 18:43:58 +00:00
|
|
|
-- create shadow bodys
|
|
|
|
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
|
2021-11-10 01:15:14 +00:00
|
|
|
lightWorld:newImage(image, w/2, h/2):setNormalMap(image_normal)
|
2014-10-27 18:43:58 +00:00
|
|
|
end
|
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function update(dt)
|
2014-10-27 18:43:58 +00:00
|
|
|
love.window.setTitle("Light vs. Shadow Engine (FPS:" .. love.timer.getFPS() .. ")")
|
2014-12-21 18:14:46 +00:00
|
|
|
lightWorld:update(dt)
|
2021-11-10 01:15:14 +00:00
|
|
|
lightMouse:setPosition(love.mouse.getX(), love.mouse.getY())
|
2014-10-27 18:43:58 +00:00
|
|
|
end
|
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
local function draw()
|
|
|
|
love.graphics.clear(0.21,0.21,0.21)
|
|
|
|
lightWorld:draw(function(l, t, w, h, s)
|
|
|
|
love.graphics.setColor(1, 1, 1)
|
|
|
|
love.graphics.draw(image, w/2-(image:getWidth()/2), h/2-(image:getHeight()/2))
|
|
|
|
end)
|
2014-10-27 18:43:58 +00:00
|
|
|
end
|
|
|
|
|
2021-11-10 01:15:14 +00:00
|
|
|
return {
|
|
|
|
load = load,
|
|
|
|
update = update,
|
|
|
|
draw = draw,
|
|
|
|
}
|