0

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.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Doormat23
  • 31
  • 4

2 Answers2

3

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.

  • Thanks Todd, sounds like it could be the way forward, would this method deal with alpha gradients in the images? (Im using dropshadows in the images that I dont want stacking on top of each other) – Doormat23 Aug 23 '11 at 20:56
0

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.

JCooper
  • 6,395
  • 1
  • 25
  • 31