I want to organize depth for objects in OpenGL ES 2.0 so that I can specify one object to be in front of other object(s). In OpenGL 3.0 I can use gl_FragDepth and just use uniform variable for depth, but in ES 2.0 this is not defined. What is good practice to do this in OpenGl ES 2.0?
Normally, you do not need to touch gl_FragDepth as it is calculated automatically for you. Unless you do some special tricks with it. Using the depth buffer to sort out fragments of opaque objects is not a “special trick”.
Besides, gl_FragDepth is defined even in the first version of GLSL.
To have one object rendered on top of everything (independent of the objects actual position in the scene), you can first render everything else, clear the depth buffer, then render your ‘special’ object.
What I acctually want is to specify depth for each object. Origanally it goes from first to last that is to be rendered. I just want to say which object is beyond another.
Placing objects in the scene is normally done by specifying a (different) modelview matrix for each object. That, combined with the depth buffer, takes care of visibility.
Without questioning why or what you are trying to do, you could check this out: