Scissors are in rectangles. Is there a way to change the shape of a scissor to an images outline so that a specific thing will only be drawn on that image (I was thinking maybe stencils but I honestly don't know much about all these graphic things).
Like ... would it involve a function that gets the shape if an image by ignoring all the 0 alphas?
Is there a way to make an image shaped scissor?
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: Is there a way to make an image shaped scissor?
Oh, that's how it's used. I'm telling you, I did open the wiki but didn't understand what "set's a geometry as a stencil" meant. When you led me there again I was like ??? . Then scrolled down and saw the examples.
Yes, thank you. I knew it involved a liiiiitle shader work
Code: Select all
-- a black/white mask image:
black pixels will mask, white
pixels will pass.
local mask =
love.graphics.newImage
( "mymask.png" )
local mask_shader =
love.graphics.newShader [[
vec4 effect(vec4 color, Image
texture, vec2 texture_coords, vec2
screen_coords) {
if (Texel(texture,
texture_coords).rgb == vec3(0.0))
{
// a discarded pixel wont
be applied as the stencil.
discard;
}
return vec4(1.0);
}
]]
local function myStencilFunction ()
love.graphics.setShader
(mask_shader)
love.graphics.draw(mask, 0 , 0 )
love.graphics.setShader()
end
function love .draw ()
love.graphics.stencil
(myStencilFunction, "replace" , 1 )
love.graphics.setStencilTest
( "greater" , 0 )
love.graphics.rectangle
( "fill" , 0 , 0 , 256, 256)
love.graphics.setStencilTest()
end
Who is online
Users browsing this forum: Google [Bot] and 5 guests