Need Help about texture mask !

Hello.

I’m working on this code since yesterday, and I do not understand why the first code works
Using mask file !

local cntWidth = display.contentWidth
local cntHeight = display.contentHeight
local cntX = display.contentCenterX
local cntY = display.contentCenterY

local oOver = display.newImage("world2.jpg", cntWidth, cntHeight)
oOver.x, oOver.y = cntX, cntY

local oMaskImg = graphics.newMask("telemask.png")													                    
oOver:setMask(oMaskImg)
oOver.maskX = 0
oOver.maskY = 0

But this one, using dynamic Mask doesn’t works !

local cntWidth = display.contentWidth
local cntHeight = display.contentHeight
local cntX = display.contentCenterX
local cntY = display.contentCenterY

local oOver = display.newImage("world2.jpg", cntWidth, cntHeight)
oOver.x, oOver.y = cntX, cntY

local oTexture = graphics.newTexture{ type = "maskCanvas", width = 128, height = 128 }
oTexture:setBackground(0, 0, 0)
local b = display.newCircle(0, 0, 64)
b:setFillColor(1)
oTexture:draw(b)
local o = display.newCircle(0, 0, 32)
o:setFillColor(0)
oTexture:draw(o)
oTexture:invalidate()

local oMask = graphics.newMask(oTexture.filename, oTexture.baseDir)
oOver:setMask(oMask)
oOver.maskX = 0
oOver.maskY = 0

It look’s like there is a full black mask !
A little help before I become cray :grimacing:

Thank’s

In fact,
That doesn’t work’s under windows.

And under Android dynamic mask work’s but not correctly !
The square 128x128 Texture finally will not give a square mask !

Here is a sample code using SAME static mask and dynamic mask.
both mask have same size and same polygone

local polygon = {0, 0, 106.4, 0, 109.57, 89.35, 77.33, 110.33, 0, 89.21}

local cntWidth = display.contentWidth																            
local cntHeight = display.contentHeight															
local cntX = display.contentCenterX																	 
local cntY = display.contentCenterY

local oBack = display.newRect(0, 0, cntWidth, cntHeight)										 
oBack.x, oBack.y = cntX, cntY																		 
oBack:setFillColor(1, 1, 1)


local oStaticMask = graphics.newMask("telemask.png")

local oLeft = display.newRect(0, 0, cntWidth * 0.5, cntHeight)										 
oLeft.x = cntWidth * 0.25
oLeft.y = cntHeight * 0.5
oLeft:setFillColor(1, 0, 0)
oLeft:setMask(oStaticMask)


local oTexture = graphics.newTexture({ type = "maskCanvas", width = 128, height = 128 })
oTexture:setBackground(0, 0, 0)
local alphaback = display.newRect(0, 0, oTexture.width - 6, oTexture.height - 6)
alphaback:setFillColor(0.5)
oTexture:draw(alphaback)
local p = display.newPolygon(0, 0, polygon)
oTexture:draw(p)
local oDynamicMask = graphics.newMask(oTexture.filename, oTexture.baseDir)

local oRight = display.newRect(0, 0, cntWidth * 0.5, cntHeight)										 
oRight.x = cntWidth * 0.75
oRight.y = cntHeight * 0.5
oRight:setFillColor(0, 0, 1)
oRight:setMask(oDynamicMask)
oTexture:invalidate()

And the result is under Android:

I do not understand what is the size of dynamic the mask !

PS : here is the telemask.png file :

Regarding Android, I guess it’s just that the full texture is getting used, despite having some padding. There are a couple extra parameters you can set. Here’s a random excerpt where I use this:

	local tw, th = tile_layout.GetSizes() -- n.b. assuming these are multiples of 4...
	local gw, gh = ncols * tw, (row2 - row1 + 1) * th -- ...these will be too...
	local tex, group = graphics.newTexture{
		type = "maskCanvas", width = gw, height = gh,
		pixelWidth = gw + 8, pixelHeight = gh + 8 -- ...so we can trivially add the black border and round up
	}, block:GetGroup()

Here, 8 = 4 pixels on each side (3 black + round to multiple of 4).

That’s strange about Windows. :frowning: In my tests that was the one platform where I DIDN’T get black screens (because it was allowing luminance render targets). Anything interesting about your Windows version or GPU? (Maybe I just had lenient drivers… ugh.)

Masks work fine if you understand how to use them correctly. Mask needs to be divisible by 4 (not sure why this is) and have 4px padding.

Masks need to be black and white not grey and white.