I am attempting to draw multiple rectangles and then mask those using globalCompositeOperation 'source-in' which works great, but the issue is that when i fill my rectangles they disappear... If I only have one fill() call they all draw properly but only respect the last fill style applied.
code in question -
ctx.drawImage(self.glass.mask, 256, 375);
ctx.globalCompositeOperation = 'source-in';
ctx.rect(256, 635, 256, 75);
ctx.fillStyle = "#c65127";
ctx.rect(256, 605, 256, 25);
ctx.fillStyle = "#f5f4f0";
ctx.rect(256, 565, 256, 35);
ctx.fillStyle = "#c65127";
ctx.fill();
The code above works properly. But if I do this, and remove the mask -
ctx.beginPath();
ctx.rect(0, 256, 256, 75);
ctx.fillStyle = "#c65127";
ctx.fill();
ctx.beginPath();
ctx.rect(0, 226, 256, 25);
ctx.fillStyle = "#f5f4f0";
ctx.fill();
ctx.beginPath();
ctx.rect(0, 186, 256, 35);
ctx.fillStyle = "#222";
ctx.fill();
I have each rectangle and they respect their fill styles. Problem is when I enable the mask they are no longer visible.
Is there a limitation to the number of elements you can have under globalCompositeOperation 'source-in' or am I just missing something simple?
here are some fiddles -
http://jsfiddle.net/ENtXs/ - working as expected but not respecting the fill styles.
http://jsfiddle.net/ENtXs/1/ - Removing mask to show all elements
http://jsfiddle.net/ENtXs/2/ - Adding beginPath() and fill() elements respect fill styles. ( no masking)
http://jsfiddle.net/ENtXs/3/ - Adding the mask back ( nothing shows up anymore )
http://jsfiddle.net/ENtXs/4/ - Only having one rectangle with the same code as #3 works properly.