View Full Version : Semi-transparent pixels on texture turning grey OpenGL-ES 2.0

Hank Finley
10-30-2013, 04:54 PM
I am trying to get a white outline/background texture to display behind my font textures to make them clearer on my map I have created.
To do this I have created a bitmap with the same fonts, except bold and white. This is going to provide me with a white outline(background) for my black text.

I save out the bitmap to a png file to check that it is correct, it is correct. Below is the screen shot from opening the png in fireworks)

Somewhere in between the loading of the texture and the rendering it is sticking in grey on the edges where the semi-transparent pixels are.
Below is a screenshot, the background is in the bottom left corner.

Below is my texture loader, shader and the third is the draw function which has the blend I'm using.

At the moment I just trying to get the white background rendering correctly.
How do I get rid of the grey?

public static int loadFontTexture(Bitmap bitmap)
final int[] textureHandle = new int[1];
GLES20.glGenTextures(1, textureHandle, 0);

if (textureHandle[0] != 0)
// Bind to the texture in OpenGL
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

// Set filtering

// Load the bitmap into the bound texture.
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

if (textureHandle[0] == 0)
throw new RuntimeException("Error loading texture.");
return textureHandle[0];

public static String getFontFragmentShader()
"precision highp float; \n" // Set the default precision to medium. We don't need as high of a
// precision in the fragment shader.
+ "uniform sampler2D u_Texture; \n" // The input texture.
+ "varying vec2 v_TexCoordinate; \n" // Interpolated texture coordinate per fragment.

+ "void main() \n" // The entry point for our fragment shader.
+ "{ \n"
+ " gl_FragColor = (texture2D(u_Texture, v_TexCoordinate));\n" // Pass the color directly through the pipeline.
+ "} \n";

private void drawSystemFontTextures()

mFontMVPMatrixHandle = GLES20.glGetUniformLocation(mFontTextureProgramHan dle, "u_MVPMatrix");
mFontPositionHandle = GLES20.glGetAttribLocation(mFontTextureProgramHand le, "a_Position");
mFontTextureCoordinateHandle = GLES20.glGetAttribLocation(mFontTextureProgramHand le, "a_TexCoordinate");
mTextureUniformHandle = GLES20.glGetUniformLocation(mFontTextureProgramHan dle, "u_Texture");


// Set the active texture unit to texture unit 0.
// Bind the texture to this unit.
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, glText.mFontTextureDataHandle);
// Tell the texture uniform sampler to use this texture in the shader by binding to texture unit 0.
GLES20.glUniform1i(mTextureUniformHandle, 2);

GLES20.glUniformMatrix4fv(mFontMVPMatrixHandle, 1, false, mMVPMatrix, 0);

// Pass in the position information
GLES20.glVertexAttribPointer(mFontPositionHandle, glText.POSITION_CNT_2D, GLES20.GL_FLOAT, false, glText.VERTEX_SIZE * mBytesPerFloat, glText.vertices);
GLES20.glEnableVertexAttribArray(mFontPositionHand le);

// bind texture position pointer
glText.vertices.position(glText.POSITION_CNT_2D); // Set Vertex Buffer to Texture Coords (NOTE: position based on whether color is also specified)
GLES20.glVertexAttribPointer(mFontTextureCoordinat eHandle, glText.TEXCOORD_CNT, GLES20.GL_FLOAT, false, glText.VERTEX_SIZE * mBytesPerFloat, glText.vertices);
GLES20.glEnableVertexAttribArray(mFontTextureCoord inateHandle);

// Draw the cube.
GLES20.glDrawElements(GLES20.GL_TRIANGLES, glText.indices.capacity(), GLES20.GL_UNSIGNED_SHORT, glText.indices);


Hank Finley
10-30-2013, 06:09 PM
Nevermind GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA); seems to sort the issue