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 & HelpOpenGL and 3D Libraries › Masking images using texture()
Page Index Toggle Pages: 1
Masking images using texture() (Read 1008 times)
Masking images using texture()
Dec 10th, 2008, 3:10pm
 
Hello!
Aim is to mask a loaded PImage. The only way i found is using the texture() command. The problem is now, that the mask should transform its shape (like growing 5 point vertex), but the image should stay at its old place. Right now my image is transforming every time i modify the vertex.

Is texture() the best way to do this?

Greets
Re: Masking images using texture()
Reply #1 - Dec 10th, 2008, 7:02pm
 
what's wrong with:
http://processing.org/reference/PImage_mask_.html

?
F
Re: Masking images using texture()
Reply #2 - Dec 10th, 2008, 7:07pm
 
Hm, that function seems to be static. I'll need a dynamic one, because the shape is gonna change/transform!

Greets
Re: Masking images using texture()
Reply #3 - Dec 10th, 2008, 7:30pm
 
you can use PGraphics as a mask. see:
http://processing.org/reference/createGraphics_.html

F
Re: Masking images using texture()
Reply #4 - Dec 10th, 2008, 8:15pm
 
Yeah,it works! Thanks for your help!
Re: Masking images using texture()
Reply #5 - Dec 10th, 2008, 8:59pm
 
Hmm, but, it only works with simple forms (rectangles), or am i wrong again?

Greets

Example:

PImage a;
PGraphics pg;

int counter;

void setup() {
 size(640, 480, P3D);

 a = loadImage("1.jpg");
}

void draw() {
 counter++; // Increase the counter
 pg = createGraphics(counter, 80, P3D); // transform the mask
 pg.beginDraw();
 pg.image(a, 0, 0);
 pg.endDraw();
 image(pg, 10, 10);
}
Re: Masking images using texture()
Reply #6 - Dec 10th, 2008, 9:09pm
 
I think the idea is to draw into pg a black and white shape representing the mask you want, then use the pg as a mask to your image, then draw that.
Re: Masking images using texture()
Reply #7 - Dec 10th, 2008, 9:42pm
 
Code:

PImage a;
PGraphics pg;

void setup() {
size(640, 480, P3D);
a = loadImage("test.jpg");
}

void draw() {
background( (sin(frameCount/6.0)+1)*127 );
pg = createGraphics(a.width, a.height, P3D); // transform the mask
pg.beginDraw();
pg.background( 255 );
pg.noStroke();
pg.fill(0);
pg.translate( pg.width/2,pg.height/2 );
pg.rotateX( frameCount/12.0 );
pg.rotateY( frameCount/24.0 );
pg.rect(pg.width/-6,pg.height/-6, pg.width/3,pg.height/3 );
pg.endDraw();
a.mask( pg );
image(a, 0, 0);
}


F
Re: Masking images using texture()
Reply #8 - Dec 20th, 2008, 4:41pm
 
Back again with the old problem ;(
It still wont work with that code. All i see is a colored rect painted on my background image. I wish (yeah, its christmas time..) to see my image inside of this transforming rectangle, all happening on a black background. Anyone knows help??

All the best,
tschiggi
Page Index Toggle Pages: 1