将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; }