OpenGL transparent images have black in them

后端 未结 4 626
醉酒成梦
醉酒成梦 2021-01-13 03:31

I am working on a game for Android and I was wondering why whenever I draw images with transparency there seems to always be some black added to the transparent parts. This

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-13 04:18

    I figured out how to fix it.

    I changed

    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    

    to

    GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    

    It turns out that Android pre-multiplies the alpha of textures of PNG images when you load it (making white turn gray).

    I added

    vColor.r = vColor.r * vColor.a;
    vColor.g = vColor.g * vColor.a;
    vColor.b = vColor.b * vColor.a;
    

    to my vertex shader to do the multiplying for my other colors.

提交回复
热议问题