Texture partially trasparent problem

I’m using jogl (the java wrapper of opengl) and I have a problem with some texture that are partially trasparent. The images that I use for building the texture have some parts trasparent and other parts opaque. The problem is that if there is a trasparent part of a texture and I draw an opaque part of another texture over it, I don’t see the opaque part. I read in a guide I have to draw all opaque objects first and then the trasparent objects sorted by the distance from the viewer. But in my case one texture intersects the other textures, so is not clear for me what to do.

If you’re using depth testing, bear in mind that the depth buffer is updated regardless of the alpha value unless you use alpha testing (glEnable(GL_ALPHA_TEST) and glAlphaFunc for the fixed-function pipeline, or testing the alpha component and executing a discard statement for transparent pixels when using a fragment shader).

If you just need binary transparency (opaque or transparent, nothing in between), alpha testing is the simplest solution. If you need partial transparency (blending), either primitives have to be drawn in the correct order (back to front is simplest, front to back is possible with an alpha buffer) or you have to use per-fragment techniques such as depth peeling (google it) or linked lists of fragments. Such techniques probably aren’t suitable if you only have a basic understanding of OpenGL.

To order primitives, you need to use a topological sort, and you may need to split polygons to break cycles. If you have primitives which intersect, you will have to split them along the intersection line. Binary space partitioning (BSP) trees allow you to pre-compute the relationship between primitives so that you don’t have to perform a full topological sort each frame.

Thank for your answer.
I forgot to say that with jogl I’m using the immediate mode. I didn’t know the discard statement that you suggested. If I correcly understood this statement must be used in the fragment shader. In a guide that I found it seems to work as I want to.
I’ll try to add the fragment shader to my code and see if it will work.