We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Problematic Masking in Processing
Page Index Toggle Pages: 1
Problematic Masking in Processing (Read 2153 times)
Problematic Masking in Processing
May 27th, 2010, 8:19am
 
Hi, I'm new to the processing community.

I have an issue with masking images, especially Black and white images. I'm masking one image with an Ellipse while displaying another image in the background. Here's the simplified code.

image(aut, 0, 0); //background image
ellipse(mouseX, mouseY, 300, 300);
loadPixels();
syd.mask(pixels);
image(syd, 0, 0, 1600, 900); // The image I'm masking


The mask works however I can still some image in the background where I shouldn't. This issue becomes worse when images are black and white. I'm guessing its something to do with the black and white values.

Does anyone have a solution to this issue?????

Also I'm using OPENGL if that causes extra complications

Thanks!
Re: Problematic Masking in Processing
Reply #1 - May 27th, 2010, 8:59am
 
So, you draw an image, then you draw a big circle over it, and you use the whole to mask your off-screen image before copying it on the sketch, where the circle is. Right?
The problem is that you use the whole sketch's area as mask, so every pixel in is act as a mask, hence the phantom images...
You should use another off-screen PGraphics to draw the mask.
Re: Problematic Masking in Processing
Reply #2 - May 27th, 2010, 9:05am
 
I'm not sure that I'm following waht you mean by 'off-screen' ?

Re: Problematic Masking in Processing
Reply #3 - May 27th, 2010, 9:24am
 
If my memory serves me well you can't have offscreen graphics with OpenGL; though I don't doubt that there are workarounds...
Re: Problematic Masking in Processing
Reply #4 - May 27th, 2010, 2:22pm
 
The mask doesn't have to be in OpenGL mode...
Just create a PGraphics, draw your ellipse in it, and use it as mask.
Off-screen means "not displayed", you draw in an image but user doesn't see it, he will see only the result.
Re: Problematic Masking in Processing
Reply #5 - May 27th, 2010, 10:11pm
 
I Think I may hae found a solution following both you pointers. (Thank you btw).

I'm now drawing the mask in a PGraphics object. This works however I have to use the P2D renderer. My program is running in OPENGL so there when I use the P2D is runs really slow.

I tried just running the whole program in P2D and the speed is ok but not as good as OPENGL.

does anyone know how to work around this issue? I'm just looking into PGraphicsOpenGL. Does anyone know if this is a better option?

Thanks!
Re: Problematic Masking in Processing
Reply #6 - May 28th, 2010, 1:08am
 
I can be wrong because I have limited OpenGL experience, but I think you can create a mask in P2D/JAVA2D and use it in an OpenGL sketch.
That said, I guess it can still be slow, because when you do loadPixels Processing has to copy the data from the OpenGL buffer to a Java buffer.
Page Index Toggle Pages: 1