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 › OPENGL Sketch Flickers in Absence of background();
Page Index Toggle Pages: 1
OPENGL Sketch Flickers in Absence of background(); (Read 588 times)
OPENGL Sketch Flickers in Absence of background();
Jul 2nd, 2008, 12:20am
 
I always have problems when I run an OpenGL sketch that does not include a regular call to background(); To illustrate my point, I include an example below.

This example runs fine with P3D. Not so much with OPENGL. With OPENGL, I get strange flickering, as if the framework is maintaining two different back buffers and alternating between them. (That is the way it works, right?) I cannot find an explanation of how to get around this issue. Is there no way to tell OpenGL: "Just use one buffer, not two?"

Essentially, my objective would be to render each frame, grab it as an image, and then use that image as a background for the next frame. For a 1920x1200 window, this is not feasible. Is there no way to tell OPENGL to always draw to the same back buffer, and just never clear it?

This issue seems so trivial, but I cannot find it mentioned anywhere. Am I missing something obvious?

void setup()
{
   size(400,400,P3D);
//    size(400,400,OPENGL);
   background(0);    
}

void draw()
{        
   camera(100,0,0,0,0,0,0,-1,0);
   noFill();
   
   if(frameCount%512<256)
          stroke(frameCount%512,20);
   else
          stroke(512-(frameCount%512),20);
       
   translate(
          10*cos(frameCount/54.0),
          10*sin(frameCount/64.0),
          10*cos(frameCount/74.0));
   rotateX(frameCount/30.0);
   rotateY(frameCount/33.0);
   box(40);  
}
Re: OPENGL Sketch Flickers in Absence of backgroun
Reply #1 - Jul 2nd, 2008, 11:16am
 
i don't see what you describe (but think i have before)

HOWEVER, i think that sketch does suffer from another problem which might explain why it looks different from the non-opengl version - the depth buffer. pixels aren't being drawn if there's already a pixel for that position that's closer to the camera than the new one.

there might be a hint that you can apply to disable the depth test (there is an opengl call but am not sure of the processing equivalent and am guessing it's on by default)

nice sketch btw
Re: OPENGL Sketch Flickers in Absence of backgroun
Reply #2 - Jul 2nd, 2008, 11:18am
 
hint(DISABLE_DEPTH_TEST)

http://processing.org/reference/hint_.html
Re: OPENGL Sketch Flickers in Absence of backgroun
Reply #3 - Jul 2nd, 2008, 11:27am
 
you also get a single black box in the middle of all the white boxes - when (frameCount % 512) = 256 then it uses stroke(256,20) and 256 overflows the byte for stroke colour.
Re: OPENGL Sketch Flickers in Absence of backgroun
Reply #4 - Jul 2nd, 2008, 6:24pm
 
koogs,

Thanks for taking the time to look at my issue.

I do know about the depth test issue, and have experimented with the hint() and unhint() for that flag. My real concern at the moment is the flickering.

You didn't see the flickering? Did you run the sketch with size(x,y,OPENGL)? (I posted the code as using P3D so you could see what it SHOULD look like. Please switch the commented lines in setup() to see it run under OPENGL.)

...and... holy crap-you're right! I had carelessly thought that rgb vals outside the range would snap to the nearest acceptable value. (Maybe I'd only ever seen them drop below 0.) I guess not.

Thanks again.
Re: OPENGL Sketch Flickers in Absence of backgroun
Reply #5 - Jul 2nd, 2008, 6:34pm
 
yep, ran it in opengl mode (had to import library as well as commenting in the code). and again with the depth test flag (just to see if it made a difference). no discernible flickering here. (here being winxp / processing 125 / ati graphics)

but, like i say, i have seen the flickering you spoke of before - certain xscreensaver hacks on my ubuntu / nvidia laptop would flash. apparently fixed in the latest release but i don't know what he did to fix them or whether it's in any way related.

could it be a sync issue, that it's running at the same syns rate as your monitor? try adding framerate 25 or something.
Re: OPENGL Sketch Flickers in Absence of backgroun
Reply #6 - Jul 2nd, 2008, 7:09pm
 
So, I tried the sketch on a different machine and it runs fine in OPENGL mode. I went back to re-evaluate my NVidia card's 3D settings and by switching "Buffer-flipping mode" from "Auto-Select" to "Use block transfer" I got the sketch to work as expected.

Thanks for your help with this.
Page Index Toggle Pages: 1