Draw the depth buffer as 2D image

I need to draw on the color buffer the depth buffer,in a greyscale. I try with glcopypixel, but it went wrong…
Pratically, I need to use the depth buffer as an image, so I’m looking for a command or a method to do this.

compute the depth manually. i do that for shadow cube maps, like this:

in your vs:

v_LightVector = u_LightPosition-gl_Vertex.xyz;

and in your fs:

gl_FragColor.r = length( v_LightVector );

v_LightVector is a varying vec3. instead of the light’s position, you’d need the camera’s, of course.

In fixed function, CopyTexImage to a DEPTH_COMPONENT texture.
Draw that texture as a quad back to the window, as L, A, or I values.