HELP! Blending/Alpha question!

Hi,

I hope someone can help… I trying now for hours and I always get the same result (… or worse :-[ )

I loaded a png file (with alpha channel) as a texture in opengl. the png is 24 bit+alpha but in opengl it looks like 256 colors.

the window (i use lwjgl) is 32 bit, the png is written correctly, the textureloader is the one i found in the wiki (thanx kev).

anyone knows whats wrong??

here is the original original png:

and here is the screenshot:

thanks in advance! :smiley:

chris

I had the same problem when I had OpenGL texture preference setting set lower than default.
Check(WinXP & ATI): Display properties -> Settings -> Advanced -> 3D -> OpenGL -> Custom

thanx for the tip!

again a driver issue?
well, could be but i am not sure because i havent seen this problem on my pc before (or i havent noticed :wink: ).

any other possible reasons?

chris

It looks like you’ve got the dreaded “blended-with-white-background” alpha problem. This is due to the tool that you used to save the PNG. It needs to be saved as if it were on a black background, not a white one otherwise it blends the partial alpha colours with white. For some reason.

You can do it in Photoshop but not, AFAIK, Paint Shop Pro.

Cas :slight_smile:

YES!!!

You are absolutely right: I did it with Paint Shop Pro, and now that I tried it with Photoshop it looks far better! :smiley:

Thanks a lot Cas! :smiley:

Now its blended to black and seems correct to me although you can still see vertical lines… :-/
is it due to my driver or do i miss a blending parameter?

chris

I’m not sure why it might be banding otherwise… unless you’ve somewhere somehow told OpenGL to use 16-bit textures. Or maybe you’ve specified a 16-bit display mode by accident?

Cas :slight_smile:

I got it (well part of it)!
The problem seems to be in the textureloader - which surprises me because I caught the one from the wiki.

i changed to another textureloader (which doesnt use RGBA, only RGB) and i see the colors fine (no alpha but i got the whole scale of colors).

I will try to fix the textureloader…

chris

i cant get it to work :’(
its always the same.

i might create a webstart to see if it shows correctly on other computers.

chris

Post up your texture loading code here, it might be something obvious. And the code that draws the quad.

Cas :slight_smile:

Hi,

here is the textureLoader (I tried also the one from the Wiki but I get the same result):

      
public final static int loadTexture(String path) {
            Image image = (new javax.swing.ImageIcon(Util.class.getResource(path))).getImage();

            BufferedImage tex = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_4BYTE_ABGR);
            Graphics2D g = (Graphics2D) tex.getGraphics();
            g.drawImage(image, null, null);
            g.dispose();

            // Put Image In Memory
            ByteBuffer scratch = ByteBuffer.allocateDirect(4 * tex.getWidth() * tex.getHeight());

            byte data[] = (byte[]) tex.getRaster().getDataElements(0, 0, tex.getWidth(), tex.getHeight(), null);
            scratch.clear();
            scratch.put(data);
            scratch.rewind();

            // Create A IntBuffer For Image Address In Memory   
            IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
            GL11.glGenTextures(buf); // Create Texture In OpenGL   

            GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
            // Typical Texture Generation Using Data From The Image
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
            
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, tex.getWidth(), tex.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, scratch);

            return buf.get(0); // Return Image Address In Memory
      }

And here is the code rendering the quad:


            GL11.glLoadIdentity();
            GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping

            GL11.glTranslatef(x,y,0);
                  
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
            GL11.glBegin(GL11.GL_QUADS);
            GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex2i(0,0);
            GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex2i(width,0);
            GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex2i(width,height);
            GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex2i(0,height);
            GL11.glEnd();

and here is the what i do to initialize blending & alpha:


            GL11.glEnable(GL11.GL_ALPHA_TEST); 
            GL11.glAlphaFunc(GL11.GL_GREATER, 0.0f); 
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); 

Thanks in advance,

Chris

Hm, looks fine, except you don’t need the alpha test at all.

Cas :slight_smile:

Thank you Cas!
I’ll prepare a webstart version and I’ll see how it looks on other computers.

BTW: Did you know that you can get a java webstart certificate for free? [quote]I took a good look at the list of certificate authorities known to Web Start and one stuck out: Thawte Freemail. In particular, the word “free”. I chased this down and it is indeed a free (no money) way to get a certificate for code signing.
[/quote]
Here is the link:
http://www.dallaway.com/acad/webstart/
The web page is quite old (1 year) so you might already know or it might not be for free anymore ::slight_smile:

Chris

[quote]again a driver issue?
[/quote]
It can be. I had a buggy driver for a Radeon 9500 wich refused to use 24 or 32 bit color depth in opengl. All games, even commersial ones like quake3, looked like crap. This was more than a year ago.

ok. i tried it with another computer and it runs fine.

so finally its another driver issue. i have a S3 but for sure next one will be nVidia.

Thanks for the help guys! :smiley:

chris

HHHHAAAAAAAAAHAA! If only you’d said you had an S3!

Please, just take it out and stamp up and down on it until you feel good. Then get the cheapest Nvidia card you can buy ($5 from Ebay) and say goodbye to all your worries.

Cas :slight_smile:

Well… if I only could… :-[

unfortunately its a notebook - so it probably will be difficult to take it out :wink:

i already ordered another a new one (i need a notebook because i am constantly traveling) which has nvidia grafix board - GeForce2 Go200 - not the newest one but sure will be fine for me. :smiley:

chris

It’s even more fun stamping up and down on a whole notebook ;D

Cas :slight_smile:

Heh, it wouldn’t be an 8MB S3 Savage/IX-MV would it? ;D

Yes, the only OpenGL drivers you can get for that chipset are utterly, utterly broken - don’t even bother. S3 seem to have zero interest in supporting their customers, so the lesson to learn is never buy any kit using any chips from S3.

Nowadays my S3-enabled laptop is employed as a DVD player, while I get serious work done on my nVidia-enabled desktop.

[quote]S3 seem to have zero interest in supporting their customers
[/quote]
That’s probably because they don’t exist anymore, do they? (weren’t they taken over by nVidia or something?)

[quote]That’s probably because they don’t exist anymore, do they? (weren’t they taken over by nVidia or something?)
[/quote]
No, they’re still alive, and producing mid-range DirectX 9 chipsets.

The difference between a company like S3 and NVIDIA is that while S3 drop support for anything that isn’t on sale any longer, NVIDIA are still updating Win95 drivers for the TNT2. S3 left my card with broken and semi-complete OpenGL 1.1 support, NVIDIA support OpenGL 1.5 on everything from the TNT2 upwards, and still provide OpenGL 1.4 drivers for the Riva 128.

Now that’s a company you can trust not to leave you in the lurch. ;D

Edit: Probably as a direct result of my mentioning how I (ab)use my laptop, yesterday the DVD drive stopped working. So my laptop is now just a heavy but portable web-browser.