Part of the Khronos Group
OpenGL.org

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
    Posts
    39

    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:	78 
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:	77 
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
    		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];
    }


    Code :
    public static String getFontFragmentShader()
    {
    	return
    		"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()
    {
    	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);
    }

  2. #2
    Intern Newbie
    Join Date
    Aug 2013
    Posts
    39
    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
  •