FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   double buffering / changing pixels[]
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: double buffering / changing pixels[]  (Read 1535 times)
depth

WWW Email
double buffering / changing pixels[]
« on: Dec 28th, 2003, 11:02pm »

hey all
 
i'm trying what i believe is double buffering, but i'm having a bit of trouble.  my loop() basically (in this order):
 
- draws to the screen a the contents of a buffer ('pBuffer') from the last frame
- draws new stuff over it
- saves the screen to a buffer
- draws some other stuff over that
 
it's the drawing the buffer to the screen i'm having trouble with.  i've tried both creating an int[] array and copy()ing to a BImage, but the results are the same.
 
Code:
for (int i=0; i<numPx; i++){
  pixels[i] = pBuffer[i];
}

 
works, but
 
Code:
pixels = pBuffer;

 
does not.  similarly with a BImage called 'lastframe',
 
Code:
for (int i=0; i<numPx; i++){
  pixels[i] = lastframe.pixels[i];
}

 
works, but
 
Code:
image(lastframe, 0, 0);

 
does not.  i assume i would see a speed increase if i could avoid looping through all the pixels each loop, but perhaps not.  i dunno what's going on behind the scenes.
 
i'm not sure if this is technically a bug, more likely just something about the way p5 runs and draws the loop()...?
 
any ideas?
« Last Edit: Jan 3rd, 2004, 6:28am by depth »  
fry


WWW
Re: double buffering / changing pixels[]
« Reply #1 on: Jan 8th, 2004, 6:23pm »

the problem is that the zbuffer (the buffer that stores all the info of where pixels are) is not getting reset.
 
for what you're trying to do, however, you should just use background(BImage image) at the beginning of your loop() function, which will copy everything properly for you.
 
benelek

35160983516098 WWW Email
Re: double buffering / changing pixels[]
« Reply #2 on: Jan 12th, 2004, 11:28pm »

hey depth, in case you need to do something similar in the future (but not necessarily involving a BImage), this will speedily copy a whole or part of an array:
 
Code:
System.arraycopy(Array1,0,Array2,0,arrayLength);
 
toxi_
Guest
Email
Re: double buffering / changing pixels[]
« Reply #3 on: Jan 13th, 2004, 6:31pm »

if you're still stuck with that, a working example of this technique is over here:
 
http://www.toxi.co.uk/p5/cyclo/
 
...although, it's using multiple image buffers to create the illusion of infinite moving objects. btw. ben, it'd be nice to document in the advanced reference, how to clear the Z-Buffer independently from the main pixel buffer.
 
Pages: 1 

« Previous topic | Next topic »