Is there a way to make an image shaped scissor?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Is there a way to make an image shaped scissor?

Post 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?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

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

Post by darkfrei »

:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

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

Post 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
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: No registered users and 54 guests