將png圖片作為紋理貼圖,在圖片周圍會產生黑邊,在網上查了一下,都沒有明確指出解決方法!廢話不說了,看代碼。
1.初始化
- protected void init(GL10 gl) {
- // Setup background color
- gl.glClearColor(1, 1, 1, 1);
- gl.glEnable(GL10.GL_BLEND);
- gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
-
- glEnable(GL_DEPTH_TEST);
- glEnable(GL10.GL_ALPHA_TEST); // Enable Alpha Testing (To Make BlackTansparent)
-
- glAlphaFunc(GL10.GL_GREATER,0.1f); // Set Alpha Testing (To Make Black Transparent)
-
- // Setup project matrix
- gl.glMatrixMode(GL10.GL_PROJECTION);
- gl.glLoadIdentity();
- GLU.gluOrtho2D(gl, 0.0f,1.3f,0.0f,1.0f);
- gl.glEnable(GL10.GL_TEXTURE_2D);
- gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff);
- gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
-
- tex = loadTexture(gl, bmp);
-
- // Smooth shading
-
- gl.glShadeModel(GL10.GL_SMOOTH);
- }
2.加載紋理貼圖
- protected static int loadTexture(GL10 gl, Bitmap bmp, boolean reverseRGB) {
- int[] textures = new int[1];
- glGenTextures(1, textures, 0);
- int mTextureID = textures[0];
- glBindTexture(GL_TEXTURE_2D, mTextureID);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
- glTexParameterf(GL_TEXTURE_2D,
- GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
- GL_CLAMP_TO_EDGE);
-
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
- GL_CLAMP_TO_EDGE);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
- GL_REPLACE);
- GLUtils.texImage2D(GL_TEXTURE_2D, 0, bmp, 0);
-
- bmp.recycle();
-
- return mTextureID;
- }
3.效果圖