Page 1 of 1

Is there a way to make an image shaped scissor?

Posted: Wed Oct 26, 2022 9:13 am
by Gunroar:Cannon()
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?

Re: Is there a way to make an image shaped scissor?

Posted: Wed Oct 26, 2022 11:01 am
by darkfrei

Re: Is there a way to make an image shaped scissor?

Posted: Wed Oct 26, 2022 12:23 pm
by Gunroar:Cannon()
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. :rofl:

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
Yes, thank you. I knew it involved a liiiiitle shader work :3