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 › capture Screen and modify with glgraphics
Page Index Toggle Pages: 1
capture Screen and modify with glgraphics (Read 1811 times)
capture Screen and modify with glgraphics
Apr 12th, 2010, 12:37pm
 
hi!
I have this code that copy the pixel right and make a pixel shift, i need to do with OPENGL or a similar library.
With Glgraphics works fine in a speed computer ( iMac -nvidia- 2.4 GHz) but in my poor pc runs slow (acer -ATi graphic card! 1.9 GHz)

Any idea?
thanks!

Code:



import processing.opengl.*;
import codeanticode.glgraphics.*;

GLTexture texP;

int xshift =1;

void setup()
{
 size(1024,768, GLConstants.GLGRAPHICS);
 hint( ENABLE_OPENGL_4X_SMOOTH );  
 int w = width;
 int h = height;

 texP = new GLTexture(this);
 texP.init(width, height);
 noStroke();
 background(0);

}

void draw()
{
 ellipse(mouseX,mouseY,50,50);
 pixelShift(xshift,0);

}
void pixelShift(int xshift,int yshift){

 texP.putImage(get());
 texP.loadPixels();
 texP.updateTexture();
 for (int y=1; y < height; y++) {
   for (int x=1; x < width; x++){

if ((x+xshift < width) && (x+xshift > 0)) {
 if ((y+yshift < height) && (y+yshift > 0)) {
   texP.pixels[x + (y*width)] = texP.pixels[(x+xshift)+ ((y+yshift)*width)];
 }
}

   }
 }
 texP.loadTexture();
 texP.updatePixels();
//image(texP,0,0);
 texP.render(0,0);

}





Sad
Re: capture Screen and modify with glgraphics
Reply #1 - Apr 23rd, 2010, 3:46pm
 
maybe the resolution is too high ... 1024 * 768 = 786 432 pixels  manipulated each frame...
Re: capture Screen and modify with glgraphics
Reply #2 - Apr 25th, 2010, 2:53am
 
One possible solutions -
(1) Render the image to an off-screen buffer and then use image() to copy part of the buffer to the actual screen. This would not only be faster but would be simple to implement a pixel rotation not just a shift. The downside is the amount of memory needed for the buffer.

(2) The problem with your solution is the double loop with nested if statements and multiplications in the inner loop.
It makes use of the arrayCopy() method. This method allows you to copy part or all of an array into another array. This method method calls a Java native method so is fast and using it could reduce the whole problem down to a single loop to iterate through each row.

Page Index Toggle Pages: 1