Rendering particles as GL_TRIANGLE_FANs with transparency in OpenGL
I want to render particles with hexagons that fade out to the outside. I've used a TRIANGLE_FAN for each particle.开发者_高级运维 However, the transparency doesn't look very nice.
glBegin(GL_TRIANGLE_FAN);
glColor4f(c.x, c.y, c.z, particle.temperature / 100.0);
glVertex3f(0, 0, 0);
glColor4f(0, 0, 0, 0);
glVertex3f(0.866025404 * H / 2, 0.5 * H / 2, 0);
glVertex3f(0, 1 * H / 2, 0);
// other vertices omitted
glEnd();
I get an output which is flickering and where the black transparent parts are drawn over opaque objects at some frames. How do I have to change my rendering routine to avoid this bugs?
What you're observing is particles behind others that do not get drawn because a closer Z-value is present in the Z-buffer.
You can draw your particles back to front.
You could also disable depth-testing, but standard alpha blending will not be correct. with the ALPHA/ONE mode, you'll get to accumulate all particles, so that order will not be important either.
精彩评论