Doormat23
Doormat23

Reputation: 31

How do I create non stacking alpha blending with objects in openGL

I am currently building an iPhone game using OpenGL ES 1.1 and using drawTriangleStrip to draw a big line that winds around the screen and overlaps itself quite often.

The problem I'm having is I don't want the alpha to stack up as the line overlaps itself. Currently I get alpha blending like this:

alpha-stack image

But I really want it to blend like this:

alpha-flat image

I have tried using variations of glBlendFunc but im not really having much luck. If any of you openGL gurus out there can show me how you would achieve the above blending that would be awesome.

Upvotes: 0

Views: 321

Answers (2)

JCooper
JCooper

Reputation: 6525

So you want it to blend onto the background, but only if blending onto the background hasn't already happened?

Perhaps you can accomplish this with reverse depth sorting: Render all the opaque things, then render the alpha things starting with the nearest and working down to the farthest. You'll need to set the glDepthFunc() to be GL_LESS instead of GL_LEQUAL (if that option exists in GL-ES...). Then the depth buffer should reject the alpha fragments if there's already alpha there.

Upvotes: 0

Todd Grigsby
Todd Grigsby

Reputation: 31

You're attempting to alpha blend three images over the background. You need to draw the three images to one canvas, with no alpha blend, and then alpha blend that canvas over the background.

Upvotes: 3

Related Questions