problem with transparency

I have 2 cubes, one is closer, second is further. When I look at straight ahead closer and further cubest looks strange (closer cube is too much transparency), when I rotate camera about 270 degrees second cube looks ok (it isn’t so transparent like first one):

http://img34.imageshack.us/i/55489397.jpg/

What is going on ?
My code:


//here draw some other objects

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

//here draw closer cube

glDisable(GL_BLEND); 
glEnable(GL_DEPTH_TEST); 
glDepthMask(GL_TRUE);

//here draw other objects

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

//here draw further cube

glDisable(GL_BLEND); 
glEnable(GL_DEPTH_TEST); 
glDepthMask(GL_TRUE); 

//here draw other objects

Blending does not work with depth testing.
Search the forum / the web / the wiki for details, any solution will be a “performance versus visual quality” tradeoff.

But when I glDisable(GL_DEPTH_TEST) then mine cubes are always closer then other objects - effect is horrible. I have strong computer so I don’t need to performance - what is the solution ?

Did you do what ZbuffeR said and do a search?

Before I had written here I searched.

First, in any case, opaque objects “//here draw other objects” should be drawn FIRST. This is extremely basic stuff, and you have not done it…
So what other information did you learn from your searches ?

Before I had written here I searched.

Why do people think they can say “I searched” when it’s so easy to show they didn’t? Google for “blending depth buffer”. The very first hit explains your problem in detail and the solution to it.

Thx it works but http://www.sjbaker.org/steve/omniv/alpha_sorting.html

The first fix - upon which all the other fixes depend is to make sure you draw all your opaque polygons before you draw any translucent ones. This is easy to do in most applications and solves most of the problems. The only thing that remains is when you try to render one translucent polygon behind another.

Strange - for me it works when I draw first transparent objects and then not transparent - why ? And in this article they said that I should first draw not transparent and then transparent.

…and if you change your field of view (ie rotate the scene or camera position)? I bet it does not work after that.

hm yes… you know something - could you tell ? :slight_smile:

…otherwise you have just stumbled upon a magic formula and we’d all want to know what that is.

Your magic formula could have made you rich and famous…if it wasn’t for the fact that it was just plain wrong. LOL!

I must say that I don’t understant your joke - English isn’t my national language so I don’t know what is going on.

Not my native language either.
Really alex2, just draw first opaque objects, with depth test and writes.
Really.
Then learn to learn from advices given to you.
Might require more GL knowledge than you currently have, but some solutions are full sorting of triangles, depth peeling, weighted average transparency, etc, recently discussed here :
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=294075

But in that way mine cubes are totally invisible :stuck_out_tongue: lol

And I use materials:
GLfloat MaterialBlack[] = {0.0, 0.0, 0.0, 0.5};
GLfloat MaterialSilver[] = {0.75, 0.75, 0.75, 0.5};

so I should see them