开发者

android/opengles alpha textures not semitransparent but binary transparent

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:

android/opengles alpha textures not semitransparent but binary transparent


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);


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);


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜