[LWJGL] Incredibly frustrating transparency problem. Need heIp ASAP

Alright so here’s the deal: I have fixed my code with regards to the spriting and animating, and everything now runs as smoothly as it could. The animate method works perfectly and I can animate my images with almost no problem.

However, LWJGL seems to pick and choose what to make transparent and when. I can load and use transparent images, as I have done with this smiley graphic here:

I can tile this image perfectly and scale it according to my specifications. However should I try the same with this image here:

which is transparent as well, it will load it with a white background. It looks like this:

I have seen online that you can use

glEnable(GL_BLEND); 
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

to get the image to appear transparent if it does not, but that ends up making it look like this:

I have no idea what is wrong with this image. It has transparency, just like the smiley image, but it doesn’t have transparency in LWJGL. It also bleeds even though the image size is a power of 2. So I am wondering: Could this be because the image isn’t a perfect square (i.e 32 x 32 instead of 32 x 16)? Please help

Use


		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);

When loading your texture.

I juststarted using LWJGL today :D. First off, I’m pretty sure java automaticly makes images transparent. What you can do if that white back of picture is showing, go in paint .net and make it transparent. I can do this in ms paint but is hard to explain. Hope I helped

Not at all

Thanks, but that didn’t change anything

Then I must ask to see your texture loading code.

public void loadSprites(){
		try{
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(path));
			imageWidth = texture.getImageWidth();
			imageHeight = texture.getImageHeight();
			if(spriteWidth == 0){
				spriteWidth = imageWidth;
			} if (spriteHeight == 0){
				spriteHeight = imageHeight;
			}
		} catch(FileNotFoundException e){
			System.err.println("Error G1: Texture file not found");
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}

What’s the code in [icode]TextureLoader.getTexture()[/icode]?

Also, make sure you have MAG_FILTER as well as MIN_FILTER:


         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // YOU NEED THIS LINE TOO

TextureLoader.getTexture() is a Slick method, not my own.

https://bitbucket.org/kevglass/slick/src/9d7443ec33af/trunk/Slick/src/org/newdawn/slick/opengl/TextureLoader.java?at=default

Also, inserted MAG_FILTER, still no change

Ah, well you should’ve mentioned you were using Slick.


texture.setTextureFilter(GL_NEAREST);

without GL_BLEND functions:

with GL_BLEND functions:

Going to try opening this GIMP and seeing if there is something wrong with the Alpha channels. Thanks for fixing the blur though :stuck_out_tongue:

ha sorry then

If you’ve got a black image and you draw it onto a black background, it will be… black. :persecutioncomplex:

Try changing the colour of either the image or the background.

The worst thing is that I knew that beforehand but forgot to actually change it because I couldn’t get the image working correctly. Thanks Hero

Such is the internet.

Well I must be that one 37 year old “kid” that doesn’t exist. :wink: Nothing wrong with using an animated image of Roy from the IT Crowd to express a “duh” moment.

And why does it matter so much to you? Let people be, its just the internet.

I didn’t post it for amusement, I posted to express how stupid of me that was. Something wrong with that? :-\

You must be in a bad mood. I would say something like this: How can some kid not laugh at this?
I mean, probably everyone here who actually read the whole thread laughed when they saw that conclusion…

I kind-of saw it coming, but I was hoping that OP would notice and fix it themselves