Can Android openGL PNG texture be translucent?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Can Android openGL PNG texture be translucent?

Postby dohuon » Tue Mar 31, 2009 5:41 am

Hi, I am developing 2D game using openGL ES on android.

For the texture, I am using PNG file. One advantage of PNG file is it can make transparent background.
I know that unlike GIF, PNG can make pixel translucent. (On other words, alpha level of pixel can be various in PNG)

Here is my problem.

The background (totally transparent section) can be transparent but I cannot make a pixel transluent with alpha level.

Image
Captured from image editor

See the pixel in the red rectangular. It is translucent.


Image
Captured from emulator (on the sky color background)

See that translucent pixels become black color pixel.


I was digging this problem for few days and found below source comment

"//It seems like alpha is currently broken in Android..."

orignal source (converting ARGB to RGBA)
http://www.pragmaticprogrammer.com/titles/eband
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         protected static ByteBuffer makeByteBuffer(Bitmap bmp) {
  2.                 ByteBuffer bb = ByteBuffer.allocateDirect(bmp.getHeight()*bmp.getWidth()*4);
  3.                 bb.order(ByteOrder.BIG_ENDIAN);
  4.                 IntBuffer ib = bb.asIntBuffer();
  5.  
  6.                 for (int y = 0; y < bmp.getHeight(); y++)
  7.                         for (int x=0;x<bmp.getWidth();x++) {
  8.                                 int pix = bmp.getPixel(x, bmp.getHeight()-y-1);
  9.                                 // Convert ARGB -> RGBA
  10.                                 byte alpha = (byte)((pix >> 24)&0xFF);
  11.                                 byte red = (byte)((pix >> 16)&0xFF);
  12.                                 byte green = (byte)((pix >> <img src="http://www.anddev.org/images/smilies/cool.png" alt="8)" title="Cool" />&0xFF);
  13.                                 byte blue = (byte)((pix)&0xFF);
  14.                                                                
  15.                                 // It seems like alpha is currently broken in Android...
  16.                                 ib.put(((red&0xFF) << 24) |
  17.                                            ((green&0xFF) << 16) |
  18.                                            ((blue&0xFF) << <img src="http://www.anddev.org/images/smilies/cool.png" alt="8)" title="Cool" /> |
  19.                                            ((alpha&0xFF))); //255-alpha);
  20.                         }
  21.                 ib.position(0);
  22.                 bb.position(0);
  23.                 return bb;
  24.         }
  25.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


According to hise comment, I guess alpha channel does not work......


I need to use translucent effect for smooth image layer effect

IS it true that android openGL does not support alpha level? Is it problem of android or opengl?
Is there any way to go around this problem?

If you have any idea, please share some idea :)
Attachments
proba.PNG
proba.PNG (5.96 KiB) Viewed 1649 times
prob.PNG
prob.PNG (18.95 KiB) Viewed 1649 times
dohuon
Freshman
Freshman
 
Posts: 3
Joined: Tue Mar 31, 2009 3:43 am

Top

Postby MrSnowflake » Tue Mar 31, 2009 5:57 pm

* This is not a turorial, MOVED *

Did you try it on a device? It might very well work on a G1.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby dohuon » Fri Apr 03, 2009 2:40 am

Sorry for misplacing post.

Yes, I tried on G1 and did not work for same reason.

MrSnowflake wrote:* This is not a turorial, MOVED *

Did you try it on a device? It might very well work on a G1.
dohuon
Freshman
Freshman
 
Posts: 3
Joined: Tue Mar 31, 2009 3:43 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 12 guests