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 › GLGraphics: Faster pixel coping between textures
Page Index Toggle Pages: 1
GLGraphics: Faster pixel coping between textures (Read 2002 times)
GLGraphics: Faster pixel coping between textures
May 20th, 2010, 9:17am
 
Code:
import codeanticode.glgraphics.*;
import processing.opengl.*;

GLGraphicsOffScreen one;
GLTexture oneTex,twoTex;

int w=400,h=200;
void setup(){
 
 size(w*2,h,GLConstants.GLGRAPHICS);
 one = new GLGraphicsOffScreen(this, w, h);

 oneTex = new GLTexture(this,w,h);
 twoTex=new GLTexture(this,w,h);//
}

void draw(){
 
 one.beginDraw();
 one.background(100,100,255);
 one.fill(255,0,0);
 one.ellipse(mouseX,mouseY,20,20);
 one.endDraw();

 oneTex=one.getTexture();
 image(oneTex, 0,0);

 // ------------------------------------------
 // copying pixels form one texture to another

 oneTex.loadPixels();
 oneTex.updateTexture();

 twoTex.loadPixels();
 twoTex.updateTexture();

 for (int i = 0; i < w*h; i++) {
   if(red(oneTex.pixels[i])>127){
     twoTex.pixels[i]=color(255);
   }
 }
 
 oneTex.loadTexture();
 oneTex.updatePixels();

 twoTex.loadTexture();
 twoTex.updatePixels();

 image(twoTex,w,0);

 // CLEAR twoTex
 twoTex.loadPixels();
 twoTex.updateTexture();

 for (int i = 0; i < w*h; i++)
   twoTex.pixels[i]=color(0); // CLEAR twoTex SCREEN

 twoTex.loadTexture();
 twoTex.updatePixels();
}



is there any better way to copy and process pixels from one texture to another. What I am doing is video frame calculations. Ant this code seems to work slow.

Thanks
Re: GLGraphics: Faster pixel coping between textures
Reply #1 - Jun 4th, 2010, 8:49am
 
Any replies to this. I too would be happy to know about this interesting code...
Re: GLGraphics: Faster pixel coping between textures
Reply #2 - Jun 4th, 2010, 1:44pm
 
I am not really sure what you want to do with your code the fastest way to do this is probably to write a pixelshader. Than you draw the video texture into a framebuffer using the shader. In the shader you check the color of every pixel from the video texture and define the output color as needed.
Page Index Toggle Pages: 1