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  ) 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!  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
|
|
|
|
|
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  ). any other possible reasons? chris
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
princec
|
 |
«
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 
|
|
|
|
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!  Thanks a lot Cas!  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
|
|
|
|
|
princec
|
 |
«
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 
|
|
|
|
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
|
|
|
|
|
chris
Senior Newbie 
lwjgl rocks!
|
 |
«
Reply #7 - Posted
2004-07-07 00:36:31 » |
|
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
|
|
|
|
|
princec
|
 |
«
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 
|
|
|
|
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();
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();
IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(buf); GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0)); 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); } |
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); 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!
|
|
princec
|
 |
«
Reply #10 - Posted
2004-07-07 20:16:48 » |
|
Hm, looks fine, except you don't need the alpha test at all. Cas 
|
|
|
|
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? 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  Chris
|
|
|
|
|
tom
|
 |
«
Reply #12 - Posted
2004-07-07 23:35:24 » |
|
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.
|
|
|
|
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!  chris
|
|
|
|
|
princec
|
 |
«
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 
|
|
|
|
chris
Senior Newbie 
lwjgl rocks!
|
 |
«
Reply #15 - Posted
2004-07-08 08:52:29 » |
|
Well... if I only could...  unfortunately its a notebook - so it probably will be difficult to take it out  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.  chris
|
|
|
|
|
princec
|
 |
«
Reply #16 - Posted
2004-07-08 09:42:04 » |
|
It's even more fun stamping up and down on a whole notebook  Cas 
|
|
|
|
cfmdobbie
|
 |
«
Reply #17 - Posted
2004-07-08 14:06:53 » |
|
Heh, it wouldn't be an 8MB S3 Savage/IX-MV would it?  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.
|
|
|
erikd
|
 |
«
Reply #18 - Posted
2004-07-09 12:32:16 » |
|
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?)
|
|
|
|
cfmdobbie
|
 |
«
Reply #19 - Posted
2004-07-09 16:01:35 » |
|
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.  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.
|
|
|
the2bears
|
 |
«
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
|
|
|
|
|