I have modified things to be a little simpler, or so I thought.
I have tried creating 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)
[ATTACH=CONFIG]530[/ATTACH]
Somewhere in between the loading of the texture and the rendering it is sticking in grey on the edges. Below is a screenshot, I have only rendered the white background in the bottom left corner.
[ATTACH=CONFIG]531[/ATTACH]
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
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
// Load the bitmap into the bound texture.
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
}
if (textureHandle[0] == 0)
{
throw new RuntimeException("Error loading texture.");
}
return textureHandle[0];
}
public static String getFontFragmentShader()
{
return
"precision highp float;
" // Set the default precision to medium. We don't need as high of a
// precision in the fragment shader.
+ "uniform sampler2D u_Texture;
" // The input texture.
+ "varying vec2 v_TexCoordinate;
" // Interpolated texture coordinate per fragment.
+ "void main()
" // The entry point for our fragment shader.
+ "{
"
+ " gl_FragColor = (texture2D(u_Texture, v_TexCoordinate));
" // Pass the color directly through the pipeline.
+ "}
";
}
private void drawSystemFontTextures()
{
GLES20.glUseProgram(mFontTextureProgramHandle);
mFontMVPMatrixHandle = GLES20.glGetUniformLocation(mFontTextureProgramHandle, "u_MVPMatrix");
mFontPositionHandle = GLES20.glGetAttribLocation(mFontTextureProgramHandle, "a_Position");
mFontTextureCoordinateHandle = GLES20.glGetAttribLocation(mFontTextureProgramHandle, "a_TexCoordinate");
mTextureUniformHandle = GLES20.glGetUniformLocation(mFontTextureProgramHandle, "u_Texture");
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
GLES20.glEnable(GLES20.GL_BLEND);
// Set the active texture unit to texture unit 0.
GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
// 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
glText.vertices.position(0);
GLES20.glVertexAttribPointer(mFontPositionHandle, glText.POSITION_CNT_2D, GLES20.GL_FLOAT, false, glText.VERTEX_SIZE * mBytesPerFloat, glText.vertices);
GLES20.glEnableVertexAttribArray(mFontPositionHandle);
// 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(mFontTextureCoordinateHandle, glText.TEXCOORD_CNT, GLES20.GL_FLOAT, false, glText.VERTEX_SIZE * mBytesPerFloat, glText.vertices);
GLES20.glEnableVertexAttribArray(mFontTextureCoordinateHandle);
// Draw the cube.
glText.indices.position(0);
GLES20.glDrawElements(GLES20.GL_TRIANGLES, glText.indices.capacity(), GLES20.GL_UNSIGNED_SHORT, glText.indices);
GLES20.glDisable(GLES20.GL_BLEND);
}