Code: Select all
-- the image size is 1024*768,the app size is 1024*768 too
function love.load()
assert(love.graphics.isSupported('pixeleffect'), 'Pixel effects are not supported on your hardware. Sorry about that.')
effect = love.graphics.newPixelEffect [[
extern Image img;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
{
vec4 pixel1 = Texel(img,texture_coords);
vec4 pixel = Texel(texture, texture_coords);
if (pixel1.r >0)
{
pixel.a = 0;
}
return pixel;
}
]]
ColourBackGround = love.graphics.newImage("back.png")
BlackWhitebackGround = love.graphics.newImage("backwb.png")
Mask = love.graphics.newImage("amask.png")
canvasMask = love.graphics.newCanvas(1024,768)
-- canvasMask:clear()
-- love.graphics.setBlendMode('alpha')
-- love.graphics.setCanvas(canvasMask)
love.graphics.draw(Mask,0,0)
--love.graphics.setColor(0,0,0,255)
-- love.graphics.circle("fill",100,100,50,100)
love.graphics.setCanvas()
effect:send("img",canvasMask)
canvas = love.graphics.newCanvas(1024,768)
love.graphics.setCanvas(canvas)
love.graphics.draw(ColourBackGround,0,0)
love.graphics.setCanvas()
end
function love.draw()
--love.graphics.draw(canvasMask, 0, 0)
love.graphics.draw(canvas, 0, 0)
love.graphics.setPixelEffect(effect)
love.graphics.draw(BlackWhitebackGround, 0, 0)
love.graphics.setPixelEffect()
--]]
love.graphics.print( 'fps: '..love.timer.getFPS(), 10,10 )
end
function love.mousepressed(x,y,button)
--effect:send('area',{x,})
canvasMask:renderTo(function()
--canvasMask:clear()
love.graphics.setBlendMode('alpha')
love.graphics.setCanvas(canvasMask)
love.graphics.draw(Mask,0,0)
--love.graphics.setColor(0,0,0,255)
love.graphics.circle("fill",x,768-y,50,100)
end)
local data = canvasMask:getImageData()
Mask = love.graphics.newImage(data)
--effect:send("img",canvasMask)
end