Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use stencils while effect is active. #47

Open
RuairiD opened this issue Feb 11, 2019 · 1 comment
Open

Cannot use stencils while effect is active. #47

RuairiD opened this issue Feb 11, 2019 · 1 comment

Comments

@RuairiD
Copy link

RuairiD commented Feb 11, 2019

The following code crashes:

local moonshine = require('moonshine')
local effect = moonshine(moonshine.effects.crt)
local stencilFunction = (function ()
    love.graphics.rectangle('fill', 100, 100, 100, 100)
end)


function love.draw()
    effect(function ()
        love.graphics.setColor(1, 1, 1, 1)
        love.graphics.stencil(stencilFunction, "replace", 1)
        love.graphics.setStencilTest("greater", 0)
        love.graphics.rectangle('fill', 0, 0, 300, 300)
        love.graphics.setStencilTest()
    end)
end

...with the following error:

Error: main.lua:11: Drawing to the stencil buffer with a Canvas active requires either stencil=true or a custom stencil-type Canvas to be used, in setCanvas.
stack traceback:
	[string "boot.lua"]:637: in function <[string "boot.lua"]:633>
	[C]: in function 'stencil'
	main.lua:11: in function 'func'
	moonshine/init.lua:68: in function 'effect'
	main.lua:9: in function 'draw'
	[string "boot.lua"]:513: in function <[string "boot.lua"]:493>
	[C]: in function 'xpcall'

I was able to fix this by adding 'stencil=true' when calling love.graphics.setCanvas within chain.draw i.e.

diff --git a/init.lua b/init.lua
index 431c6c0..cb58a12 100644
--- a/init.lua
+++ b/init.lua
@@ -63,7 +63,7 @@ moonshine.chain = function(w,h,effect)
     local fg_r, fg_g, fg_b, fg_a = love.graphics.getColor()

     -- draw scene to front buffer
-    love.graphics.setCanvas((buffer())) -- parens are needed: take only front buffer
+    love.graphics.setCanvas{(buffer()), stencil=true} -- parens are needed: take only front buffer
     love.graphics.clear(love.graphics.getBackgroundColor())
     func(...)

Shall I make a PR for this?

@Xella37
Copy link

Xella37 commented Mar 23, 2019

I think this is fixed. I'm able to use stencils within the shader without using "stencil=true".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants