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 & HelpSyntax Questions › Code does not work in OPENGL
Page Index Toggle Pages: 1
Code does not work in OPENGL (Read 2079 times)
Code does not work in OPENGL
Dec 24th, 2009, 4:23am
 
Hi, I try to experiment a little bit with loadPixels and updatePixels and I don't know why that code works in every render mode, except OPENGL...  Undecided can anyone tell me why?

import processing.opengl.*;

int[] tmpFrame;

void setup() {
 colorMode(HSB);
 frameRate(30);
 size(600, 600, OPENGL);
 noStroke();
 smooth();
 tmpFrame = new int[width * height];
 background(0);
 fill(240, 0, 250);
}

void draw() {

 ellipse(mouseX, mouseY, 20, 20);      

 loadPixels();
 work(pixels, tmpFrame, width, height);
 arrayCopy(tmpFrame, pixels);
 updatePixels();
}


void work(int[] src, int[] dst, int w, int h) {

 int c;
 int r, g, b;

 for(int i = 0; i < src.length; i++){
   dst[i] = (src[i] << 1);
 }

}
Re: Code does not work in OPENGL
Reply #1 - Dec 24th, 2009, 4:53am
 
could be because with opengl all the rendering is done on the graphics card and processing doesn't have (easy / quick) access to the pixels
Re: Code does not work in OPENGL
Reply #2 - Dec 25th, 2009, 1:38am
 
Well... but how to solve it?  Sad
Re: Code does not work in OPENGL
Reply #3 - Dec 25th, 2009, 2:35am
 
I don't know well OpenGL, but a possible way might be to draw the pixels in a PGraphics and use it as a texture.
If I am wrong, 3D specialists just correct me.
Re: Code does not work in OPENGL
Reply #4 - Dec 26th, 2009, 5:02am
 
Hmm... reference says its not allowed to create PGraphics with opengl... Sad
Re: Code does not work in OPENGL
Reply #5 - Dec 26th, 2009, 6:38am
 
Precisely for the reasons above, I suppose. PGraphics are off-screen graphics, so an OpenGL version makes no sense, since the latter is managed by GPU, ie. on screen.
But I was thinking of making a graphic in some other mode (ie. make a good old bitmap) then using it, if possible, in OpenGL.
Re: Code does not work in OPENGL
Reply #6 - Dec 27th, 2009, 1:15pm
 
Problems are always around when not updating the background when using OPENGL renderer.

if you put a background() command in the begining of draw(), the drawing is done, but, of course, you loose the original and nicer drawings...

To where my knowledge goes, I think there is no workaround for this.
Re: Code does not work in OPENGL
Reply #7 - Dec 28th, 2009, 12:04am
 
Its a pity that it wont work, like I imagined *G*

anyway Tongue

thanks for all your answers Smiley
Page Index Toggle Pages: 1