Hello. This is the case: I generate a texture with an alpha channel and lay it on all the planes of the cube. The problem is that through some absolutely transparent ( alpha channel=0 ) areas on the planes of the cube other other planes are not visible. By the torsion method of the cube :) I realized that it depends on the order of the textures on the edges in the display() function. For example, if you look through the last in the order of the overlay texture, then through it you can see all the other faces, and if you look at the cube through the first in the order of the overlay, the other faces are not visible.

I would very much like the rest of the cube to look through the rest of the cube, but I don’t know how to do it. The code is big in it is garbage (link below). Maybe the screenshots will help.

alt text

alt text

Thank you for your attention and help.

Dynamic Cube code .

    1 answer 1

    Yes, the fact is that, depending on the order of rendering, the back faces are discarded because they do not pass the depth test, and if the depth test were turned off, they would be drawn over the front ones, which is also not the correct behavior.

    In the general case, it is impossible to do without sorting translucent edges by depth. First you need to draw the farthest, then the closest. With the included dough depth and blending, of course. There is another advanced way - Depth peeling . If I do not confuse anything, this is when the scene is drawn entirely (without sorting the triangles as such), but several times with different depth cut-off planes, then they are displayed in layers. The quality depends on the number of passes.

    For a cube and other convex translucent polyhedra, I would advise you the following approach:

    1. Enable clipping of the back edges ( glEnable(GL_CULL_FACE) if you have OpenGL ).
    2. Draw only back edges (first glCullFace(GL_FRONT) , then RenderCube ).
    3. Draw only the front faces (first glCullFace(GL_BACK) , then RenderCube again).
    • one
      By the way, if you do not have semi-transparent edges, and the alpha channel jumps discretely from 0 to 1.0f, as in the example you cited, the Alpha test will work fine (in OpenGL it looks like this: glEnable (GL_ALPHA_TEST); glAlphaFunc (GL_GEQUAL, 0.5); - this means that if the alpha value is in the texture from 0 to 0.5, nothing will be drawn, in 0.5-1.0 it will be drawn.) The blending itself is not even needed in this case. - allcreater