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 › trail....trai....tra...tr...t...
Page Index Toggle Pages: 1
trail....trai....tra...tr...t... (Read 2231 times)
trail....trai....tra...tr...t...
Jul 27th, 2009, 10:57am
 
Hi to all, i'm asking to opengl master if is possible to recreate the trail effect in "pure" opengl... in normal processing environment i pretty simple: basicly is to draw a semi-transparent rect instead to redraw the complete scene, i love this effect!!!

example in P2D
void draw()
{
 fill(0,0,0,8); //mostly transparent black
 rect(0,0,width,height); // slowly fades anythign drawn previously.
 image(myimg,xpos,ypos);
//...... other draw stuff
}


but with opengl doesn't work. Maybe is a stupid question but i'd like to use opengl power to speed up my app...

thanks...
Re: trail....trai....tra...tr...t...
Reply #1 - Jul 27th, 2009, 12:58pm
 

but with opengl doesn't work.


doesnt it ?

Code:
import processing.opengl.*;

void setup(){
 size(500,500,OPENGL);
 background(0);
 noStroke();

}
void draw()
{
 fill(0,0,0,8);  
 rect(0,0,width,height);  
 fill(255);
 ellipse(mouseX,mouseY,20,20);

}
Re: trail....trai....tra...tr...t...
Reply #2 - Jul 28th, 2009, 3:40am
 
yes..... unfortunally this way to make "trails" works only with "plain" processing....

opengl redraw every frame deleting the ghost effect... the code runs but the effect doesn't  Undecided
Re: trail....trai....tra...tr...t...
Reply #3 - Jul 28th, 2009, 3:54am
 
so when you use this piece of code it doesnt work for you

this is how it looks like for me, Click on it, its a video...

...
Re: trail....trai....tra...tr...t...
Reply #4 - Jul 28th, 2009, 9:52am
 
To clarify, using the "OPENGL" mode in Processing is faster than the default 2D, or P3D, but it's not as fast as straight OpenGL.  To use that, you need to initialze an openGL object, align the GLUperspective to match Processing, etc.
Here is an example of this:
http://benhem.com/games/GLP5align
And this is what the following code looks like, in action:
http://benhem.com/games/GLfade

Here is  the code you need, for reference in case I move those demos:

Quote:
import processing.opengl.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;

GL  gl;
GLU glu;
float aspect, camZ, xx, yy;

void setup(){
  size(400,400,OPENGL);
  aspect=(float)width/(float)height;
  camZ=((height/2.0) / tan(PI*60.0/360.0));
  glu = new GLU();
  gl = ((PGraphicsOpenGL)g).gl;
}

void draw(){
  gl.glMatrixMode(GL.GL_PROJECTION);
  gl.glLoadIdentity();
  glu.gluPerspective(180/3.0, aspect, camZ/10.0, camZ*10.0);
  glu.gluLookAt(0, 0, camZ, 0, 0, 0, 0, 1, 0);

  gl.glColor4f(0,0,0,.02);
  gl.glBegin(GL.GL_TRIANGLE_STRIP);
  gl.glVertex3f(-width/2,-height/2,0);
  gl.glVertex3f(width/2,-height/2,0);
  gl.glVertex3f(-width/2,height/2,0);
  gl.glVertex3f(width/2,height/2,0);
  gl.glEnd();
  
  xx=mouseX-width/2;
  yy=mouseY-width/2;
  
  gl.glColor3f(1,1,1);
  gl.glBegin(GL.GL_TRIANGLE_STRIP);
  gl.glVertex3f(xx-20,yy-20,0);
  gl.glVertex3f(xx+20,yy-20,0);
  gl.glVertex3f(xx-20,yy+20,0);
  gl.glVertex3f(xx+20,yy+20,0);
  gl.glEnd();
}



// enjoy -- Ben
Re: trail....trai....tra...tr...t...
Reply #5 - Jul 28th, 2009, 11:16am
 
@ cedric.... really strange! I have a macbook pro 2,33.... maybe is the videocard??? mmmmh something to check....

@ ben: thank you. the example you provide me is what i want! now i'm going to merge with my code....

Re: trail....trai....tra...tr...t...
Reply #6 - Jul 28th, 2009, 12:48pm
 
Bruzz, i also have a Macbook Pro 2.33 with ATI X1600 and get the very same issue like you, but only when using P5 1.x.x.

Beta versions are working fine with this code.

It might be related to P5 1.x.x OpenGL lib.
Re: trail....trai....tra...tr...t...
Reply #7 - Jul 29th, 2009, 12:54am
 
So the "ghost" disappear when the beta goes out. I think the best solution is to to the trail effect in "pure java" to avoid this kind of probelms.....

now is time code... thank you all....

ciao
Re: trail....trai....tra...tr...t...
Reply #8 - Aug 3rd, 2009, 2:34pm
 
The "proper" way to do it which works even with clearing the screen each frame is gl.glAccum(...) and related methods, there should be threads on the boards about them if you search.
Page Index Toggle Pages: 1