GLGraphics alpha masks support?
in
Contributed Library Questions
•
1 year ago
Hi,
I'm trying to mask a texture (webcam image) with a drawn mask. I'd like to get the same effect as the
processing mask function.
However working with a grayscale image doesn't seem to work. I now draw the mask with a cutout (breakshape) to make my mask working, however I cannot soften the edges.
See code below:
- // Generate maskTexture
- maskTex = new GLTexture(parent, imageSize, imageSize);
- // Generate maskedTexture
- maskedTex = new GLTexture(parent, imageSize, imageSize);
- // Generate mask and store it in maskTex
- pg = createGraphics(imageSize, imageSize, JAVA2D);
- pg.beginDraw();
- //background(gray, alpha);
- //pg.background(255,255); //white
- pg.background(0, 0); // black
- pg.smooth();
- //fill(gray, alpha)
- //pg.fill(255, 255, 0); // yellow
- pg.fill(0, 255);
- pg.noStroke();
- pg.beginShape();
- pg.vertex(0, 0);
- pg.vertex(imageSize, 0);
- pg.vertex(imageSize, imageSize);
- pg.vertex(0, imageSize);
- pg.breakShape();
- // order is important
- pg.vertex(int(x2+translateX), int(y2+translateY));
- pg.vertex(int(x1+translateX), int(y1+translateY));
- pg.vertex(int(x3+translateX), int(y3+translateY));
- pg.endShape(CLOSE);
- pg.endDraw();
- //pg.filter(BLUR, 12);
- maskTex.putImage(pg);
- maskFilter.apply(new GLTexture[] {eyeTex, maskTex}, maskedTex);
With the mask method in Processing I just drew a triangle and blurred it and it work fine. Below the drawing code. I'd like to be able to use this as a mask in GLgraphics (softened edges).
- // Generate mask
- pg = createGraphics(imageSize,imageSize,JAVA2D);
- pg.beginDraw();
- pg.background(0); // black
- pg.smooth();
- pg.noStroke();
- pg.fill(255);
- pg.pushMatrix();
- pg.translate(translateX, translateY);
- pg.triangle(x1, y1, x2, y2, x3, y3);
- pg.popMatrix();
- pg.endDraw();
- pg.filter(BLUR, 4);
Can I use alpha masks with GLGraphics ? And if yes how?
And if not why I still see a stroke of 1 pixel when masking?
I'd like to keep using GLGraphics because its way faster.
The code I currently use (uses GSVideo and GLgraphics):
1