Canvas & Stencil in Love 11.0

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Canvas & Stencil in Love 11.0

Post by pgimeno »

Maybe try to contact the Scrale author? Personally I have never used it.
User avatar
Jack Dandy
Prole
Posts: 49
Joined: Mon Sep 08, 2014 4:26 pm

Re: Canvas & Stencil in Love 11.0

Post by Jack Dandy »

Just to be sure, I tried making a simple program, where a stencil is used on a canvas.
No involvement of Scrale.

If you'll try it, you can see the stencil doesn't work. (If you uncomment the 1st line and the last 3 lines in love.draw, you can see it for yourself)
Any tips?

Code: Select all


local function myStencilFunction()
   love.graphics.rectangle("fill", 225, 200, 350, 300)
end
 
 function love.load()
   
   canvas_main = love.graphics.newCanvas()
   
  
      
 end
 
 
function love.draw()
  love.graphics.setCanvas({canvas_main, stencil=true})
  
    -- draw a rectangle as a stencil. Each pixel 'above' the rectangle will have its 'stencil value' set to 1. The rest will be 0.
    -- Note the 'above' bit. In order for the stencil to take effect, the things effected by it should appear AFTER the stencil shape, 
    -- and INSIDE the 'setStencilTest' sandwich.
    love.graphics.stencil(myStencilFunction, "replace", 1)   
    love.graphics.setColor(255, 255, 255, 255)
    --White background
    love.graphics.rectangle('fill',0,0,love.graphics.getWidth(),love.graphics.getHeight()) -- Things outside the 'StencilTest' sandwich will NOT be effected.
 
   -- Beginning of 'stencilTest' sandwich.
   -- Only allow rendering on pixels which have a 'stencil value' smaller than 1.
    love.graphics.setStencilTest("less", 1)
 
    love.graphics.setColor(255, 0, 0, 255)
    love.graphics.circle("fill", 300, 300, 150, 50)
 
    love.graphics.setColor(0, 255, 0, 255)
    love.graphics.circle("fill", 500, 300, 150, 50)
 
    love.graphics.setColor(0, 0, 255, 255)
    love.graphics.circle("fill", 400, 400, 150, 50)
    
    -- Ending of 'stencilTest' sandwich.
    -- using the "setStencilTest()" function again as seen below, closes and "sandwiches" the entire stencil department. This is how you use it!
    love.graphics.setStencilTest() 
    
    
    love.graphics.setColor(0, 0, 0, 255)
    -- Black line going across the screen
    love.graphics.rectangle('fill',0,love.graphics.getHeight()/2,love.graphics.getWidth(),10) -- Things outside the 'StencilTest' sandwich will NOT be effected.
    
    love.graphics.setCanvas()
    love.graphics.setColor(1,1,1)
    love.graphics.draw(canvas_main)
end
MissDanish wrote: Thu Apr 05, 2018 10:55 pm btw canvases are broken in 11.0 unless you use the fix smile linked in the 11.0 release thread. Sometimes they refuse to draw on screen
Can you link me to that fix? I can't seem to find it.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Canvas & Stencil in Love 11.0

Post by pgimeno »

Jack Dandy wrote: Tue Jul 09, 2019 6:18 pm Just to be sure, I tried making a simple program, where a stencil is used on a canvas.
No involvement of Scrale.

If you'll try it, you can see the stencil doesn't work. (If you uncomment the 1st line and the last 3 lines in love.draw, you can see it for yourself)
Any tips?

Code: Select all

[...]
The code you've posted works for me the same, with and without canvas. Sounds like a graphics driver issue.

Jack Dandy wrote: Tue Jul 09, 2019 6:18 pm
MissDanish wrote: Thu Apr 05, 2018 10:55 pm btw canvases are broken in 11.0 unless you use the fix smile linked in the 11.0 release thread. Sometimes they refuse to draw on screen
Can you link me to that fix? I can't seem to find it.
https://love2d.org/forums/viewtopic.php ... 03#p219603

That's already fixed in 11.1.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 40 guests