PDA

View Full Version : Blending makes my entire texture disappear!



KanadaKid
08-20-2009, 03:36 PM
Hi,

I am trying to blend a small texture (PNG file; 16x25, but I properly scale that for OpenGL in my program) in my scene. The image itself contains pixels that are transparent. However, when I use the traditional blending scheme as I have used for the rest of my textures (that is, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), OpenGL seems to blend away the entire texture. I'm using OpenGL 2.0 and SDL.

I set up my projection via:
glOrtho(0, 640, 480, 0, -1, 1);

The modelview matrix doesn't have any transformations/rotations applied to it. Furthermore, I have disabled depth testing as this is just a 2D game.

I don't understand what's wrong, considering all of my other textures blend just fine. I tried some more testing, and even with a blank scene, the texture disappears when drawn with blending enabled. However, without blending, the texture is drawn, including the useless black pixels around it that should have been blended as transparency.

I'm not sure if I was too clear, and if so, I can provide more information. Any ideas?

todayman
08-20-2009, 09:20 PM
I'm currently working on a similar project, and I also had some problems at the beginning with textures, but I don't actually remember what the symptoms were...

I'm fairly sure this (http://www.opengl.org/resources/faq/technical/texture.htm) is the page that solved it. Question 21.030 about the texture evironment.

scratt
08-20-2009, 10:01 PM
Doesn't Photoshop do something weird to PNGs transparency layer?
Are you using Photoshop? I know it can mess up compressed textures, and I remember having to load and re-save some PNGs from Photoshop in a slightly different format way back...

KanadaKid
08-21-2009, 02:03 AM
Yep, scratt you were right. :P I resaved my files, and magically they work perfectly now. Weird...

Thanks for the help everyone!

ZbuffeR
08-21-2009, 02:47 AM
Be sure to set glColor to full white and opaque, before drawing textured object, as it is multiplied by texture values in texture blend mode.
glColor3f(1.0f,1.0f,1.0f); // alpha defaults to 1
or
glColor4f(1.0f,1.0f,1.0f,1.0f);

And reload your png texture in gimp or photoshop, and check that the extra channel is correct.

EDIT: too slow, ok :)