Android OpenGL and non premultiplied textures

| | August 4, 2015

As I understand it; by default all bitmaps will will get the alpha channel premultiplied in Android if loaded using BitmapFactory.

My setup:
I have a 32bit bitmap(.bmp) where the alpha channel has a gloss map and the rgb is a specular map.

I found out that I can load the bitmap without being premultiplied using the bitmap option:
opts.inPremultiplied = false;

When I render the alpha channel of the texture like this in the shader:
gl_FragColor.rgb = vec3(texture.a);

The resulting mesh is all white and not shades of gray as expected.

I upload the texture with this method:
GLUtils.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image, 0);

I have also tried using this approach
as well with the same result although I might have done something wrong there.

Can anyone spot where I have gone wrong or what else I need to do?

Thanks on beforehand!

One Response to “Android OpenGL and non premultiplied textures”

  1. It is very likely that your bmp loader does not load the alpha channel and fills it with a default value, as BMP with alpha channel is non-standard. Try using a .png file instead. From wikipedia:

    “An integrated alpha channel has been introduced with the undocumented BITMAPV3INFOHEADER and with the documented BITMAPV4HEADER (since Windows 95) and is used within Windows XP logon and theme system as well as Microsoft Office (since v2000); it is supported by some image editing software, such as Adobe Photoshop since version 7 and Adobe Flash since version MX 2004 (then known as Macromedia Flash). It is also supported by GIMP, Google Chrome, Microsoft PowerPoint and Microsoft Word.”

Leave a Reply