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 & HelpPrograms › Using Offscreen PGraphics!
Page Index Toggle Pages: 1
Using Offscreen PGraphics?! (Read 398 times)
Using Offscreen PGraphics?!
Mar 4th, 2006, 10:35am
 
i basicly want to make what draw() does when you don't include background().. an image where you can draw shapes (with alpha and smooth)

I made this little sketch which is sortof supposed to append one image to another.. the biggest problem i'm having is making a PGraphics object to draw to.. just like g.
The only class i can make it work with is PGraphics3, which doesn't support smooth, and looks like has problems with fill as well (just try it out in my code)

Any leads on how i could work with PGraphics objects as I do with the g object?
G3.ellipse, with fill, stroke and smooth, basicly, preferably not PGraphics3 object

Code:

PImage G;
PGraphics3 G3;

void setup()
{
size(200,200);
framerate(10);
smooth();
G = new PImage(width,height);
G3 = new PGraphics3(width,height,null);
}

void draw()
{
G3.beginFrame();
G3.pixels = new int[width*height];
G3.stroke(255,10);
G3.ellipse(random(width),random(height),10,10);
G3.endFrame();

background(255,0,0);
G = append(G,G3);
image(G,0,0);
//if(mousePressed) image(G3,0,0);
}

PImage append(PImage src, PImage img)
{
if(src.pixels.length != img.pixels.length) return src;
for(int i = 0; i < src.width; i++){
for(int j = 0; j < src.height; j++){
color cSrc = src.pixels[i+j*src.width];
color cNew = img.pixels[i+j*src.width];
float rS = red(cSrc);
float rN = red(cNew);
float gS = green(cSrc);
float gN = green(cNew);
float bS = blue(cSrc);
float bN = blue(cNew);
float aS = alpha(cSrc);
float aN = alpha(cNew);
if(aN > 0) // comment out if sentence for cool effect
src.pixels[i+j*src.width] = cSrc+cNew; //blend(cSrc,cNew,ADD);
}
}
src.updatePixels();
return src;
}
Re: Using Offscreen PGraphics?!
Reply #1 - Mar 4th, 2006, 11:15pm
 
You can make things work a lot easier by using G3.defaults() then you can just do image(G3,0,0) without having to do a pixel copy.

I think you can use any PGraphics2/3/GL/whatever if you remember the .defaults() call before you do any work on it.
Page Index Toggle Pages: 1