Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Semi-transparent pixels on texture turning grey OpenGL-ES 2.0

  1. #1
    Intern Newbie
    Join Date
    Aug 2013

    Semi-transparent pixels on texture turning grey OpenGL-ES 2.0

    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)
    Click image for larger version. 

Name:	font_background.jpg 
Views:	212 
Size:	19.1 KB 
ID:	1175

    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.
    Click image for larger version. 

Name:	screenshot.jpg 
Views:	170 
Size:	21.7 KB 
ID:	1176

    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?

    Code :
    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];

    Code :
    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";

    Code :
    private void drawSystemFontTextures()
        mFontMVPMatrixHandle = GLES20.glGetUniformLocation(mFontTextureProgramHandle, "u_MVPMatrix");
    	mFontPositionHandle = GLES20.glGetAttribLocation(mFontTextureProgramHandle, "a_Position");
        mFontTextureCoordinateHandle = GLES20.glGetAttribLocation(mFontTextureProgramHandle, "a_TexCoordinate");
    	mTextureUniformHandle = GLES20.glGetUniformLocation(mFontTextureProgramHandle, "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);
    	// 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);
        // Draw the cube.
        GLES20.glDrawElements(GLES20.GL_TRIANGLES, glText.indices.capacity(), GLES20.GL_UNSIGNED_SHORT, glText.indices);

  2. #2
    Intern Newbie
    Join Date
    Aug 2013
    Nevermind GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA); seems to sort the issue

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts