Reputation: 2140
I'm rendering elements in OpenGL ES and they have the same color, but a different alpha. The problem is that when the alpha is .1, the color changes, not just the opacity. For example, the color will change from black to purple when the alpha component is set to a value of 0.1. When the alpha value is not .1, or some other tenth values, it works fine.
I'm setting this blending prior to drawing:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
Drawing:
// if the element has any data, then draw it
if(vertexBuffer){
glVertexPointer(2, GL_FLOAT, sizeof(struct Vertex), &vertexBuffer[0].Position[0]);
glColorPointer(4, GL_FLOAT, sizeof(struct Vertex), &vertexBuffer[0].Color[0]);
glTexCoordPointer(2, GL_FLOAT, sizeof(struct Vertex), &vertexBuffer[0].Texture[0]);
glDrawArrays(GL_TRIANGLES, 0, [element numberOfSteps] * [element numberOfVerticesPerStep]);
}
Upvotes: 1
Views: 202
Reputation: 43379
This is normal behavior for pre-multiplied alpha (which your blend function implies). You must change color and alpha together when you use pre-multiplied alpha.
Thus, the new color should be equal to originalColor * alpha
whenever you change the value of alpha
. Note, you should use the floating-point normalized value of alpha (e.g. 0.0 - 1.0) and not the fixed-point value (e.g. 0 - 255)
Notice how the more traditional blend equation already performs SrcRGB * SrcA? Your particular blend equation only works correctly if the RGB components are literally pre-multiplied by the alpha component.
Upvotes: 1