grit
YaBB Newbies
Offline
Posts: 5
Erase Pixels from an Image in OpenGL
Oct 21st , 2008, 7:25pm
Hello, I'm pretty new to processing and java. I want to erase pixels from a displayed picture with the mouse (or through another controling). My first attempt is to use the mask of PImage and turn certain pixels in the mask black, in order to make the corresponding pixels in the image becoming transparent. This works well with the P3D renderer. However, I would like to have the same effect in OpenGL mode, because this would be faster. I have searched in this forum already and found something about offscreen buffers in OpenGL with glColorMask. http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1215499566 http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1183577125 But I don't understand how to integrate this - how to specify the size of the GL-buffer, how to manipulate the pixels and how to use it as a mask for an image. Can anybody help me and give an example? Thanks a lot! Here is my code using a PGraphics buffer with createGraphics in P3D mode (wipe with the mouse to see what's behind the image): PImage bg, im; PGraphics mask; void setup() { size(1024,768,P3D); bg = loadImage("bg.jpg"); im = loadImage("01.jpg"); mask = createGraphics(im.width,im.height,P3D); for(int i=0;i<mask.pixels.length;i++){ mask.pixels[i]=color(255); } im.mask(mask); } void draw() { loadPixels(); image(bg,0,0); image(im,0,0); if(mousePressed) { wipe(); } } void wipe(){ mask.beginDraw(); mask.stroke(0); mask.strokeWeight(20); mask.line(mouseX, mouseY, pmouseX, pmouseY); mask.endDraw(); im.mask(mask); }