Copying Depth Buffer To Texture

Hi!
I want to do DoF, and I need to send to the shader a texture with the depth valuse.
How can I copy the z-buffer to texture?

Create an FBO and a depth texture, set depth texture on FBO, bind FBO, render to it, unbind FBO, bind system FB, rebind texture to shader sampler, render with it.

And FoD? Assume you mean DoF?

If you for some reason don’t want to use render-to-depth-texture, you can also use
glCopyTex(Sub)Image2D() do copy the depthbuffer contents over into a depth-texture. The internal format of the depth texture will automatically cause the depthbuffer to be copied over (instead of the colorbuffer contents).

You right, I don’t want to render to (depth) texture. Because, I can’t render my geometries twice every time.
When you say glTexImage2D() with depth format, do you mean like that:
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

Yes, you create the texture

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

and later on you copy the depthbuffer contents into it:

glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, 0,0, m_width, m_height);

When we suggested to use render-to-depth-texture, we didn’t mean to render the scene twice; instead, you may also use a depthtexture as depthbuffer-replacement right from the beginning.

It works!
Thank you all