PDA

View Full Version : Alpha blending problem



MSobiecki
10-21-2006, 02:12 PM
Hello, I've got a small (I think so) problem - I enable blending in my program

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);Then I render some stuff, two quads, one of them is related to mouse movement. They have the same z-axis orientation. The upper quad's (in depth buffer) alpha channel is set to 0.1f. When the lower quad is moved under the other one, I simply can't see it, the blending doesn't work. GL_BLEND is enabled for sure. I don't know what to do. The same situation is with alpha channels in sprites - they ain't working.

ZbuffeR
10-22-2006, 12:03 AM
Do not forget you still have depth test enabled :)
Very similar question solved here :
http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=2;t=020827

Post here again if you need more help.

MSobiecki
10-22-2006, 02:57 AM
I disabled the depth test, but it didn't make it. I think that I have two problems related - the first one is described before, and other one is that it doesn't matter if I do like this:

glBegin(GL_QUADS);
/*quad 1*/
glEnd();
glBegin(GL_QUADS);
/*quad 2*/
glEnd();or like this:

glBegin(GL_QUADS);
/*quad 2*/
glEnd();
glBegin(GL_QUADS);
/*quad 1*/
glEnd();becouse quad 2 is always on top ;/ When I enable depth test, the quad which is lower is the one that is rendered later - and it's wrong, I want the first one to be rendered lower.
I know that I must have forgotten about something, but I can't find out what this something is ;)

MSobiecki
10-22-2006, 03:58 AM
Ok, I solved it. The reason for wrong hierarchy was
depth func set to GL_LESS not to GL_LEQUAL - in 2D games i suppose GL_LESS is useless (maybe I'm wrong ;p)
I also solved the problem with transparency, but I really don't know how Oo, I tried many different things and it started to work, when I changed them in the backward order it still worked, so I don't know what the problem was.
Ok thank you for help ;) Greets

arekkusu
10-22-2006, 08:30 AM
Depth testing is disabled by default. 2D games generally don't need a depth buffer at all.