View Full Version : Problem with triangles intersection with alpha value. Need Help!

11-17-2004, 11:22 PM

I would like to draw triangles (with the same Y - up direction - value), which ones may intersect each other. When I draw it with alpha value, I see darker blobs.
How can I resolve it?
screenshot:: http://delfin.unideb.hu/~fazekaim/problem.jpg

I have a plane quad (in red colors), and above the quad a lot of randomly generated triangles with the same Y(up direction) value.


11-18-2004, 09:27 AM
Hi !

I would guess that you have messed up the winding order of some of the traiangles, some are clockwise and some are counter clockwise, triangles has two sides...


11-18-2004, 12:36 PM
It looks more like a zfighting problem mixed with blending.
Disable depth test, to see if it gets uniformly dark.
To sort that out properly, you can use the stencil buffer when drawing your grey triangles.
Increment stencil on draw, and set the stencil test to =0 or something like that. So that each pixel of the screen will only be drawn once.

11-18-2004, 03:39 PM
Stencil buffer? Sounds good. How can I use it to eliminate the intersections?

11-18-2004, 04:05 PM
I used stencil like this:

gl.glDepthMask( false );
gl.glEnable( GL.GL_STENCIL_TEST );
gl.glStencilFunc( GL.GL_ALWAYS, 1, 0xFFFFFFFF);
gl.glStencilOp( GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP );

for (Triangle triangle : shadow) {
gl.glVertex3f(triangle.triples[0].x, triangle.triples[0].y, triangle.triples[0].z);
gl.glVertex3f(triangle.triples[1].x, triangle.triples[1].y, triangle.triples[1].z);
gl.glVertex3f(triangle.triples[2].x, triangle.triples[2].y, triangle.triples[2].z);
gl.glEnd( );

gl.glDepthMask( true );

gl.glDisable( GL.GL_STENCIL_TEST );

I couldn't resolved the alpha mixing problem.
Have I made mistakes using stencil buffer?

11-20-2004, 04:05 PM
mistakes ? yes :

// test passes only if stencil is equal to 0 :
gl.glStencilFunc( GL.GL_EQUAL, 0, 0xFFFFFFFF);
// increment on draw :
gl.glStencilOp( GL.GL_INCR, GL.GL_INCR, GL.GL_INCR );

Post an updated screenshot if you still have troubles.

Edit: and don't forget to clear stencil between frames : glClear(GL_STENCIL_BUFFER_BIT);