Page 1 of 1

setStencil to a circle not clipping quad

Posted: Sun Feb 15, 2015 3:11 am
by vortizee
I’m very new to this so pardon if I make a fundamental error.
The stencil: within an overall rectangle, image based pieces draw over a grid image clipped by a circle.

Code: Select all

  scope_stencil = function()
    love.graphics.setColor( 0, 0, 0, 255 )
    love.graphics.circle( 'fill', 322.5, 319.5, 611)
  end
The grid consists of a background image filling the whole circle, over which quads will be drawn, and hopefully clipped if they go beyond the circular stencil (scope).

Code: Select all

function love.draw()
--------------------
  love.graphics.draw( mainScreen, 0, 0 )      -- the overall background
  love.graphics.setColor( 0, 0, 0, 255 )
  love.graphics.printf( “Some Text“, 774, 13, 130, "center" )
  love.graphics.setColor( 255, 255, 255, 255 )
  
  love.graphics.setStencil( scope_stencil )    -- limit drawing to inside the scope
    love.graphics.setColor(255, 255, 255, 255)
    love.graphics.draw( maskScreen, 17, 14 )	--  17,  14 = scope center - is clipped to stencil if test drawn out of center
    love.graphics.draw( thimage, img_apts[1], 308, 305 )	-- 308, 305 = central grid
    love.graphics.draw( thimage, img_apts[7], 48, 152 )      -- is not clipped outside the stencil !!
  love.graphics.setStencil()
end

maskscreen — a circular texture of the grid (transparent outside) is successfully clipped by the stencil if I draw it off-center, but quad img_apts[7] which is partly outside the stencil isn’t clipped; the whole 29x29 quad is drawn. Why is the stencil failing there?

Re: setStencil to a circle not clipping quad

Posted: Sun Feb 15, 2015 4:56 am
by Positive07
When you use an image with setStencil, the square of the image is used, that means that the stencil becomes a square with the dimensions of the image. Try using love shapes, circle, rectangle and such, they do work

Re: setStencil to a circle not clipping quad

Posted: Sun Feb 15, 2015 5:05 am
by vortizee
But the stencil is already a shape: love.graphics.circle( ‘fill’, 322.5, 319.5, 611)

Re: setStencil to a circle not clipping quad

Posted: Mon Feb 16, 2015 1:57 am
by vortizee
Positive07 wrote:When you use an image with setStencil, the square of the image is used, that means that the stencil becomes a square with the dimensions of the image. Try using love shapes, circle, rectangle and such, they do work
Image

Here’s a diagram of the problem I’m getting with the posted code: The stencil is one big circle; the green area is a background image the size of the stencil drawn offset to the upper left for test purposes — successfully clipped by the stencil. The yellow quad is a game piece image placed to test adherence to the stencil at the edge — it goes beyond the stencil.

So why does the stencil work for the green image and not the quad image?

Re: setStencil to a circle not clipping quad

Posted: Tue Feb 17, 2015 11:31 am
by vortizee
My bad, left over garbage from considering an image-based stencil specified diameter instead of radius. Clips like the devil.