I am experiencing an issue on Android with OpenGL ES 3.1. I wrote an application that shows a liquid falling down from the top of the screen. This liquid is made of many particles that are a bit transparent, but the color using alpha blending are displayed differently on another phone.
The color of every drop is defined as follow:
private int particleColor = Color.argb(50, 0, 172, 231);
Each particle color is stored in a buffer:
private ByteBuffer colorBuffer = ByteBuffer.allocateDirect(MAX_PARTICLES * PARTICLE_COLOR_COUNT).order(ByteOrder.nativeOrder());
And this buffer is passed to the OpenGL entity to be drawn:
/**
* Binds the data to OpenGL.
* @param program as the program used for the binding.
* @param positionBuffer as the position buffer.
* @param colorBuffer as the color buffer.
*/
public void bindData(LiquidShaderProgram program, ByteBuffer positionBuffer, ByteBuffer colorBuffer){
glVertexAttribPointer(program.getPositionAttributeLocation(), POSITION_COMPONENT_COUNT, GL_FLOAT, false, POSITION_COMPONENT_COUNT * OpenGLUtils.BYTE_PER_FLOAT, positionBuffer);
glEnableVertexAttribArray(program.getPositionAttributeLocation());
glVertexAttribPointer(program.getColorAttributeLocation(), COLOR_COMPONENT_COUNT, GL_UNSIGNED_BYTE, true, COLOR_COMPONENT_COUNT, colorBuffer);
glEnableVertexAttribArray(program.getColorAttributeLocation());
}
The rendering is down by calling this function:
/**
* Render the liquid.
* @param particleCount as the particle count.
*/
public void draw(int particleCount) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDrawArrays(GL_POINTS, 0, particleCount);
glDisable(GL_BLEND);
}
The fragment shader just draw the color that it receives:
precision mediump float;
varying vec4 v_Color;
void main() {
if (length(gl_PointCoord - vec2(0.5)) > 0.5) {
discard;
} else {
gl_FragColor = v_Color;
}
}
It works very well on one phone (Nexus 5X):
But on another phone (Galaxy S10), with the exact same code, the color is not the same:
Does anyone has any idea about a way to solve this issue? I would like to display the correct color on the second phone as well.