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- loadPixel the cffscreen image[SOLVED]
Page Index Toggle Pages: 1
glGraphics- loadPixel the cffscreen image?[SOLVED] (Read 2405 times)
glGraphics- loadPixel the cffscreen image?[SOLVED]
Mar 22nd, 2010, 9:09pm
 
Hi,
I'd like to know if that's possible to load the pixels of the offscreen's image (glTexture).
In the code below, it is! but it's like if it was taking the first frame only... I'm quite confused about this one..

thanks

Code:
import processing.opengl.*;
import damkjer.ocd.*;
import codeanticode.glgraphics.*;

GLGraphicsOffScreen o;

GLTexture srcTex, bloomMask, destTex;
GLTexture tex0, tex2, tex4, tex8, tex16;

GLTextureFilter extractBloom, blur, blend4, toneMap;

Camera cam;

void setup(){
 size(720, 480, GLConstants.GLGRAPHICS);
 hint( ENABLE_OPENGL_4X_SMOOTH );  

 // Loading required filters.
 extractBloom = new GLTextureFilter(this, "ExtractBloom.xml");
 blur = new GLTextureFilter(this, "Blur.xml");
 blend4 = new GLTextureFilter(this, "Blend4.xml");  
 toneMap = new GLTextureFilter(this, "ToneMap.xml");

 destTex = new GLTexture(this, width, height);

 // Initializing bloom mask and blur textures.
 bloomMask = new GLTexture(this, width, height, GLTexture.FLOAT);
 tex0 = new GLTexture(this, width, height, GLTexture.FLOAT);
 tex2 = new GLTexture(this, width / 2, height / 2, GLTexture.FLOAT);
 tex4 = new GLTexture(this, width / 4, height / 4, GLTexture.FLOAT);
 tex8 = new GLTexture(this, width / 8, height / 8, GLTexture.FLOAT);
 tex16 = new GLTexture(this, width / 16, height / 16, GLTexture.FLOAT);

 cam = new Camera(this, 0, 0, 300);

 o = new GLGraphicsOffScreen(this, width, height, true, 4);

 frameRate(30);
}

void draw(){
 float fx = 0.2;
 float fy = 0.4;

 srcTex = o.getTexture();

 o.beginDraw();
 o.background(0);
 cam.circle(0.05);
 cam.feed();

 o.stroke(0);

 o.pushMatrix();
 o.rotateX(QUARTER_PI);
 o.rotateY(-QUARTER_PI);
 o.rotateZ(QUARTER_PI);
 o.fill(255,0,0);
 o.box(140);
 o.popMatrix();

 o.pushMatrix();
 o.fill(50,50,50);
 o.box(150);
 o.popMatrix();

 o.endDraw();

 // Extracting the bright regions from input texture.
 extractBloom.setParameterValue("bright_threshold", fx);
 extractBloom.apply(srcTex, tex0);

 // Downsampling with blur.
 tex0.filter(blur, tex2);
 tex2.filter(blur, tex4);    
 tex4.filter(blur, tex8);    
 tex8.filter(blur, tex16);    

 // Blending downsampled textures.
 blend4.apply(new GLTexture[]{tex2, tex4, tex8, tex16}, new GLTexture[]{bloomMask});
 
 // Final tone mapping into destination texture.
 toneMap.setParameterValue("exposure", fy);
 toneMap.setParameterValue("bright", fx);
 toneMap.apply(new GLTexture[]{srcTex, bloomMask}, new GLTexture[]{destTex});


 image(destTex, 0, 0, width, height);

 ///////////////////////////////////////////
 ///////////////////////////////////////////
 //THE PROBLEM ..
 
 int halfImage = width*height/2;
 loadPixels();
 for (int i = 0; i < halfImage; i++) {
   pixels[i+halfImage] = pixels[i];
 }
 updatePixels();

}
Re: glGraphics - loadPixel the cffscreen image ?
Reply #1 - Mar 24th, 2010, 9:51pm
 
Sorry for the late reply. The function that copies the texture back into the pixels is called updateTexture().

So you should do the following:

Code:

 updateTexture();
 updatePixels();
 int halfImage = width*height/2;
 loadPixels();
 for (int i = 0; i < halfImage; i++) {
   pixels[i+halfImage] = pixels[i];
 }
 updatePixels();
Re: glGraphics - loadPixel the cffscreen image ?
Reply #2 - Mar 25th, 2010, 1:31pm
 
thanks a lot for your reply ac.
the solution you just mention makes an NullpointerException from RunnerException....
anyways.. that happen because of the updatePixel() command.
do you know why?

thanks
Re: glGraphics - loadPixel the cffscreen image ?
Reply #3 - Mar 25th, 2010, 4:03pm
 
my mistake, loadPixels() should be called before updatePixels():

Code:

 loadPixels();
 updateTexture();
 updatePixels();
 int halfImage = width*height/2;
 for (int i = 0; i < halfImage; i++) {
   pixels[i+halfImage] = pixels[i];
 }
 updatePixels();
Re: glGraphics - loadPixel the cffscreen image ?
Reply #4 - Mar 25th, 2010, 8:12pm
 
unfortunately it still don't do it.  Embarrassed

When you call updatePixels() twice, it seems to invert the the first frame (up side down)! Again and again, for each frames...

I looked at GLTexture documentation and i found the loadTexture() function and also putPixels(). Are these useful for my situation? Anyways, I tried these but nothing's working ... i guess thats logical.

Do you still have any idea about this topic?

thanks again ac
Re: glGraphics - loadPixel the cffscreen image ?
Reply #5 - Mar 26th, 2010, 12:47am
 
sorry, I actually didn't look your code carefully enough the first time.

If what you want is to copy the (opengl) texture into the pixels array, then do some modifications in the array and finally copy the modified pixels back into the texture, then this what you should do, before rendering the texture with image(destTex...), is the following:

Code:

 destTex.loadPixels();
 destTex.updateTexture();
 int halfImage = width*height/2;
 for (int i = 0; i < halfImage; i++) {
   destTex.pixels[i+halfImage] = destTex.pixels[i];
 }
 destTex.loadTexture();
 destTex.updatePixels();


GLTexture.updateTexture() copies the texture into the pixels array, while GLTexture.loadTexture does exactly the opposite (pixels to texture). Does this solve your problem?
Re: glGraphics - loadPixel the cffscreen image ?
Reply #6 - Mar 26th, 2010, 3:31am
 
Hi guys, and if i need this steps

- capure the screen
- Modifications in the pixel array
- put again the pixel array to screen

the same like that but in opengl
Code:

void pixelShift(int xshift, int yshift) {
 loadPixels();
 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)) {
         pixels[x + (y*width)] = pixels[(x+xshift)+ ((y+yshift)*width)];
       }
     }

   }
 }
 updatePixels();
}


[SOLVED] glGraphics - loadPixel the cffscreen image ?
Reply #7 - Mar 29th, 2010, 9:47am
 
Thank you very much AC. Again you resolved my problem!
You were right, I was doing it the wrong way.
your last post did the trick real good.

thanks again
Page Index Toggle Pages: 1