setStencil to a circle not clipping quad

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
vortizee
Prole
Posts: 34
Joined: Sat Feb 14, 2015 6:23 am

setStencil to a circle not clipping quad

Post 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?
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: setStencil to a circle not clipping quad

Post 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
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
vortizee
Prole
Posts: 34
Joined: Sat Feb 14, 2015 6:23 am

Re: setStencil to a circle not clipping quad

Post by vortizee »

But the stencil is already a shape: love.graphics.circle( ‘fill’, 322.5, 319.5, 611)
User avatar
vortizee
Prole
Posts: 34
Joined: Sat Feb 14, 2015 6:23 am

Re: setStencil to a circle not clipping quad

Post 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?
User avatar
vortizee
Prole
Posts: 34
Joined: Sat Feb 14, 2015 6:23 am

Re: setStencil to a circle not clipping quad

Post by vortizee »

My bad, left over garbage from considering an image-based stencil specified diameter instead of radius. Clips like the devil.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests