KB-20071209-028
From Triled Wiki
- Status: respond received
- author: Ariel Malka
- link: http://groups.google.com/group/android-developers/msg/62014cb5f89effe9
- Description: OpenGL smoothing artifacts. Instead of expected smoothed by blending, dithered edges are rendered.
- Steps to reproduce:
Taken from original post:
1. get data from resources.
Bitmap image =
BitmapFactory.decodeStream(getResources().openRawResource(R.raw.translucent_128));
int sourceW = source.width();
int sourceH = source.height();
int textureW = nextPowerOfTwo(sourceW);
int textureH = nextPowerOfTwo(sourceH);
int[] pixels = new int[sourceW];
byte[] data = new byte[textureW * textureH];
int i = 0;
for (int y = 0; y < sourceW; y++)
{
source.getPixels(pixels, 0, sourceW, 0, y, sourceW, 1);
for (int x = 0; x < sourceW; x++)
{
data[i++] = (byte) (pixels[x] & 0xff);
}
i += textureW - sourceW;
}
ByteBuffer buffer = ByteBuffer.wrap(data);
2. Transform the data into a texture:
gl.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_ALPHA, textureW,
textureH, 0, GL11.GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
gl.glTexParameterx(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER,
GL11.GL_LINEAR);
gl.glTexParameterx(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER,
GL11.GL_LINEAR);
gl.glTexParameterx(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S,
GL11.GL_CLAMP_TO_EDGE);
gl.glTexParameterx(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_CLAMP_TO_EDGE);
3. draw the texture:
gl.glDisable(GL11.GL_LIGHTING);
gl.glShadeModel(GL11.GL_FLAT);
gl.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
gl.glEnable(GL11.GL_BLEND);
gl.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
gl.glColor4f(0f, 0f, 0f, 1f); // WILL DRAW THE TEXT IN BLACK
