opengl-esalphablendingandroidglblendfunc

Why does OpenGL blending not work on HTC Desire?


Does anyone know how to enable blending in OpenGL (android) on a HTC Desire. I am trying to draw colored triangles and using the alpha value of the color buffer to blend them with the background (or another triangle).

It works both on the emulator (2.1) and on a htc hero 2.1 but not on my desire with 2.2. Is there some hardware difference between a hero and a desire that causes this?

The main stuff from the code is (not in order):

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

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

private final static float[] colors = {
       1f, 0f, 0f, 0.5f, // point 0 red
       1f, 0f, 0f, 0.5f, // point 1 red
       1f, 0f, 0f, 0.5f, // point 2 red
       1f, 0f, 0f, 0.5f, // point 3 red

       1f, 0f, 0f, 0.5f, // point 4 red
       1f, 0f, 0f, 0.5f, // point 5 red
       1f, 0f, 0f, 0.5f, // point 6 red
       1f, 0f, 0f, 0.5f, // point 7 red
};

PS. I can provide more code if someone needs it...


Solution

  • Jonas, your comment about lighting seems right on, and so now I think we have an answer. The OpenGL ES 1.1.12 Specification states The value of A produced by lighting is the alpha value associated with dcm, where dcm is the material diffuse color.

    If you have enabled COLOR_MATERIAL, then the material diffuse color and material ambient color both are taken from the current vertex color. This would imply the Desire is incorrect, and the emulator is correct.

    If you have disabled COLROR_MATERIAL (the default state), then the diffuse color material is set with glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, ptrTo4Floats). This would imply that the Desire is correct, and the emulator is incorrect.