Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  HELP! Blending/Alpha question!  (Read 2456 times)
0 Members and 1 Guest are viewing this topic.
Offline chris

Senior Newbie




lwjgl rocks!


« Posted 2004-07-06 15:16:01 »

Hi,

I hope someone can help... I trying now for hours and I always get the same result (... or worse  Embarrassed )

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!   Cheesy

chris
Inquisitor
Guest
« Reply #1 - Posted 2004-07-06 15:42:29 »

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
Offline chris

Senior Newbie




lwjgl rocks!


« Reply #2 - Posted 2004-07-06 16:12:58 »

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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2004-07-06 17:27:12 »

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 Smiley

Offline chris

Senior Newbie




lwjgl rocks!


« Reply #4 - Posted 2004-07-06 18:47:43 »

YES!!!

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

Thanks a lot Cas!  Cheesy

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
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2004-07-06 20:28:22 »

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 Smiley

Offline chris

Senior Newbie




lwjgl rocks!


« Reply #6 - Posted 2004-07-06 21:44:49 »

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
Offline chris

Senior Newbie




lwjgl rocks!


« Reply #7 - Posted 2004-07-07 00:36:31 »

i cant get it to work  Cry
its always the same.

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

chris
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #8 - Posted 2004-07-07 09:17:53 »

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

Cas Smiley

Offline chris

Senior Newbie




lwjgl rocks!


« Reply #9 - Posted 2004-07-07 18:46:14 »

Hi,

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
      
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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
            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:
1  
2  
3  
4  
            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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2004-07-07 20:16:48 »

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

Cas Smiley

Offline chris

Senior Newbie




lwjgl rocks!


« Reply #11 - Posted 2004-07-07 22:29:40 »

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.

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   Roll Eyes

Chris
Offline tom
« Reply #12 - Posted 2004-07-07 23:35:24 »

Quote
again a driver issue?

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.

Offline chris

Senior Newbie




lwjgl rocks!


« Reply #13 - Posted 2004-07-08 00:08:34 »

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!  Cheesy

chris
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #14 - Posted 2004-07-08 00:13:07 »

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 Smiley

Offline chris

Senior Newbie




lwjgl rocks!


« Reply #15 - Posted 2004-07-08 08:52:29 »

Well... if I only could...  Embarrassed

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.  Cheesy

chris
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #16 - Posted 2004-07-08 09:42:04 »

It's even more fun stamping up and down on a whole notebook  Grin

Cas Smiley

Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #17 - Posted 2004-07-08 14:06:53 »

Heh, it wouldn't be an 8MB S3 Savage/IX-MV would it? Grin

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.

Hellomynameis Charlie Dobbie.
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #18 - Posted 2004-07-09 12:32:16 »

Quote
S3 seem to have zero interest in supporting their customers

That's probably because they don't exist anymore, do they? (weren't they taken over by nVidia or something?)

Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #19 - Posted 2004-07-09 16:01:35 »

Quote
That's probably because they don't exist anymore, do they? (weren't they taken over by nVidia or something?)


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. Grin


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.

Hellomynameis Charlie Dobbie.
Offline the2bears

Senior Member


Projects: 2


Little Bear: Code Fu!


« Reply #20 - Posted 2004-07-13 02:17:19 »

Has anyone had any luck saving a png file from The Gimp?  I'm using Gimp 2.0 and I've been unable to create textures with the proper colour depth... I'm getting what looks like 256 as well - though Alien Flux views just fine.  I'm using SPGL, Sprites and the SpriteEngine so it's not my texture loading code.

If anyone's done this, kindly tell me how to save my png files properly.  Or what other free tool to use;)

Thanks,

Bill

the2bears - the indie shmup blog
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (54 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!