3

I would like to draw you attention to the following pictures

First the original image

alt text

then how it is rendered on the screen

alt text

as you can see on the original everything is nice and yellow, the edges have a slight transparency to look smooth.

but when I render I have some darkened pixels that appear.

To avoid the usual answer I get

I use

gl.glTexImage2D(GL10.GL_TEXTURE_2D, level, GL10.GL_RGBA, width, height, 0, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixelBuffer);

and not the glutil tool

also

gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

Anybody has a solution for that ?

Thanks

Jason


Edit

I did some digging. in the original image my background is already the same color as the coin and I use an alpha mask. I've also checked, when I load the bitmap it seems that all the bitmap who have an alpha 0 are automatically set to 0,0,0,0. this might be the problem.


edit actually it seems to be the issue. I checked the values of the bitmap I open, the values for transparent pixels are 0,0,0,0 instead of the color I set. Is this a problem with Bitmap or how I created my image?

// Load up, and flip the texture:
            Bitmap temp = BitmapFactory.decodeResource(context.getResources(), resource, opts);
            Bitmap bmp = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), flip, true);
            temp.recycle();
Jason Rogers
  • 19,194
  • 27
  • 79
  • 112

2 Answers2

2

What is the background color of your image? i.e. what does it look like when you remove the alpha channel? I'll guess - it's black? Try giving the background color the same color as your logo (i.e. yellowish) and try again.

EDIT: May as well edit the answer based on the comments. Even if you properly set the RGB color of the surrounding pixels, some image compression formats might still "optimize" that out and turn all completely transparent pixels into (0,0,0,0), which will cause the problems you describe when using bilinear filtering. Try using a different file format, or do research to see if you can turn this feature off in that particular compression, or consider fixing up the image in code after loading.

EboMike
  • 76,846
  • 14
  • 164
  • 167
  • I did some digging. in the original image my background is already the same color as the coin and I use an alpha mask. I've also checked, when I load the bitmap it seems that all the bitmap who have an alpha 0 are automatically set to 0,0,0,0. this might be the problem. – Jason Rogers Nov 30 '10 at 06:11
  • 1
    What format is your file? Could be part of the compression - all completely transparent pixels are treated as 0,0,0,0, since the issues of bilinear filtering are normally not a concern when doing image compression. – EboMike Nov 30 '10 at 06:40
1

Your image probably has premultipled alpha values. Try using gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);

See this post for more details.

Darrell
  • 1,945
  • 15
  • 21
  • If I use gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); I don't get smooth edges anymore, I get a stair effect that looks even worst :D. but thanks to for the link, I'll check that out – Jason Rogers Nov 30 '10 at 07:04