View Full Version : Depth in OpenGL ES 2.0

09-06-2014, 10:32 AM
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?

09-06-2014, 11:21 AM
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.

carsten neumann
09-06-2014, 12:14 PM
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.

09-06-2014, 12:55 PM
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.

carsten neumann
09-06-2014, 01:04 PM
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.

Ed Daenar
09-06-2014, 03:04 PM
Without questioning why or what you are trying to do, you could check this out: