6

I am drawing some textures with alpha channel, but when they are displayed it looks like the alpha channel is only binary. So a pixel is either transparent or opaque, although in the texture file itself the pixel is half-transparent. The blending is set up like this:

gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);

Is there a workaround for this problem?

The above shows how it should be like, and the below shows how it is:

alt text

Copas
  • 5,921
  • 5
  • 29
  • 43
clamp
  • 33,000
  • 75
  • 203
  • 299
  • What internalFormat are you using in that texture? – Dr. Snoopy Sep 03 '10 at 16:07
  • Can I get more information on the PNG? Like how was it saved? – Octavian Helm Sep 06 '10 at 11:24
  • it was saved with photoshop, and believe me, it has an alpha channel with varying values. it is not binary transparent. – clamp Sep 06 '10 at 11:28
  • Would you post a link to the PNG file so I can test it with the same resources? Only if possible. – Octavian Helm Sep 06 '10 at 11:54
  • http://deviantsart.com/upload/2757n63.png but again, i dont think the PNG is the problem, because i use PNGs like this a lot in normal GL rendering and they work fine. – clamp Sep 06 '10 at 12:06
  • I didn't state that the PNG is the problem I just wanted to have the same resources to be able to reproduce the result. ;) – Octavian Helm Sep 06 '10 at 12:23
  • @clamp PNG is not an internal format. The internal format is a parameter to the glTexImage2D call. What value are you using for that parameter? – Dr. Snoopy Sep 08 '10 at 16:14

4 Answers4

3

Try this:

gl.glEnable(GL10.GL_BLEND);    
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_ALPHA_BITS);
//draw...
gl.glDisable(GL10.GL_ALPHA_BITS);
cement
  • 2,905
  • 1
  • 23
  • 20
1

It seems like it's using alpha testing instead of alpha blending, which would explain the thresholding behaviour. Although it isn't enabled by default, it might be worth to try:

gl.glDisable(GL10.GL_ALPHA_TEST);
Aert
  • 1,989
  • 2
  • 15
  • 17
0

What surface format are you using for your GLSurfaceView? Is it a translucent (not transparent) format?

surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);

Also the EGL settings must have alpha support set. This will give you the best of quality...

surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);

Edit: Another thought is that perhaps you didn't upload the image to OpenGL in a translucent format with glTexImage2D?

Moncader
  • 3,388
  • 3
  • 22
  • 28
0

Are you storing the PNG to a GL texture that only has 1 bit of alpha, such as 16-bit 5-5-5-1 format? This would cause the behavior above.