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 › Flashing screen in OpenGL
Page Index Toggle Pages: 1
Flashing screen in OpenGL (Read 934 times)
Flashing screen in OpenGL
Mar 19th, 2008, 8:20am
 
Hello. Can someone tell me why does this piece of code make my window flash like crazy?

Code:

import processing.opengl.*;

void setup(){
size(800,600,OPENGL);
background(0);
}

void draw(){
noStroke();
rect(mouseX,mouseY,50,50);
}


I want to draw squares to the screen, but they don't stay still.

This only happens when using the OPENGL renderer, and using P3D or otherwise is not an option since I also need to run some other code that needs OpenGL.

Any ideas?

I even try setting the camera at the beggining of the draw function to no avail.

Sad
Re: Flashing screen in OpenGL
Reply #1 - Mar 19th, 2008, 10:55am
 
works fine here (win xp / ATI card)

but i have seen something like you mention on my laptop (ubuntu / nvidia card) with other opengl software (xscreensaver). i have a feeling it's a double-buffering thing (it seems to flick between two different frames) but haven't confirmed that.
Re: Flashing screen in OpenGL
Reply #2 - Mar 19th, 2008, 9:50pm
 
That's weird. Although it makes sense what you say about the double buffering, cause it actually seems like it's drawing a black screen followed by a white one in rapid succession.

I found that if I use

Code:

hint(ENABLE_OPENGL_2X_SMOOTH);


things get corrected. I tried using "smooth()" alone but it won't do the trick.

Thanks anyway for checking the code koogs
Smiley
Re: Flashing screen in OpenGL
Reply #3 - Apr 5th, 2008, 1:57am
 
the reason you're getting a flashing screen is because you placed the background(0); in the setup instead of in draw.  You need to place it in draw so that it clears the screen  every frame... Unless you actually want to create trails.  It looks like opengl is only clearing one of the buffers, if you run the sketch a second time you can see some of the remains of the first run.  AA uses the second buffer for it's calculations, that's probably why that fixes it. also if you use

if (frameCount < 3) {background (0);}

at the start of your draw it fixes the flashing background but the cubes will still "move" since they're alternating every frame.
Page Index Toggle Pages: 1