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 › Alpha problem with OpenGL
Page Index Toggle Pages: 1
Alpha problem with OpenGL (Read 1594 times)
Alpha problem with OpenGL
Nov 9th, 2009, 6:58am
 
Hej,

I am writing a littel particle system and I render the particles as seen below:

Code:
    PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
GL gl = pgl.beginGL();
gl.glEnable( GL.GL_BLEND );
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);


gl.glEnable(GL.GL_POINT_SMOOTH);
gl.glPointSize(esize);

gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, posarray);
gl.glEnableClientState(GL.GL_COLOR_ARRAY);
gl.glColorPointer(4, GL.GL_FLOAT, 0, colarray);

gl.glDrawArrays(GL.GL_POINTS, 0, pmax);

gl.glDisable(GL.GL_BLEND);
pgl.endGL();


After the particles reach their maximum age I set the alpha channel to zero. But instead of turning invisible they turn to the color of the background (currently black) and can be seen when other particles fly behind them.  Cry

I tried several blend combinations without any luck and do belive that the one which I use should be right.

Any ideas how to solve this?

Thanks for reading/helping.
Re: Alpha problem with OpenGL
Reply #1 - Nov 9th, 2009, 7:08am
 
I does sound like a blend option problem to me.
Try  gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);

One easy way to cycle through all the blending combinations is to add some code like in this space junk example.  http://processing.org/discourse/yabb2/?num=1207671111
Re: Alpha problem with OpenGL
Reply #2 - Nov 9th, 2009, 7:10am
 
it would probably be better not to draw them anymore. or even remove them from your array / arraylist at all
Re: Alpha problem with OpenGL
Reply #3 - Nov 9th, 2009, 8:51am
 
Hej,

thanks for the suggestions.

@jeffq: Yeah I tried that one and again I thought it should work in the way I already wrote it. (I couldnt work out how to include the code directly because of the "nvArray". I included every library but the compiler still did not now what a "nvArray" is. Tried to rewrite it using ArrayList but then the glBlendFunc did not like strings as arguments.) Your suggestion "GL.GL_SRC_ALPHA,GL.GL_ONE" has the same problem.

@Cedric: I thought about not drawing them but when I am using vertex buffers I have to have a fixed number in the buffer, don't I? If I would use an arraylist the useage of a vertex buffer would be obsolte and therefore the rendertime would be too high.


Can it be that the problem is coming from somewhere else? For example: I use Processings "Camera". Maybe this does not work togehter with the blend modes. I will check it out.

Checked it ... the problem is still there without using the camera.

BTW Cedric, your jellyfish screenshot looks great. Smiley
Re: Alpha problem with OpenGL
Reply #4 - Nov 9th, 2009, 9:21am
 
Thanks! i am still working on the jellyfish...

so if you dont want to remove them you still dont need to draw them. lets say you have variable alpha where you store the alpha value.
then simply say

if(alpha!=0)ellipse(x,y,1,1);
so as soon as the alpha is 0 its not drawn anymore.

But i have to deal with the same problem. as you can see with the jellyfish. The thin lines should be transparent white, but as soon as they overlay the white body they turn black ( transparent/background combi)...  lets see if we can come up with a good solution here.
Re: Alpha problem with OpenGL
Reply #5 - Nov 10th, 2009, 9:24am
 
I'm not sure if this is the case, but there are sometime problems with alpha when you look from other direction thany you render which can by caused by rotation of camera. If this is the case you can try to disable some OpenGL settings

 gl.glDisable(gl.GL_LIGHTING);
 gl.glDisable(gl.GL_DEPTH_TEST);
 gl.glDisable(gl.GL_CULL_FACE);
 gl.glDisable(gl.GL_ALPHA_TEST);
 gl.glDisable(gl.GL_AUTO_NORMAL);
 gl.glDisable(gl.GL_COLOR_MATERIAL);
Page Index Toggle Pages: 1