z buffer into FBO


I’m a new programmer to Opengl,
My aim is to retrieve the depth buffer into a FBO to be able to transfer to cuda without using glReadpixels

Here is what I’ve done

void make_Fbo()
	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

void make_render_buffer()
	glGenRenderbuffers(1, &rb);
	glBindRenderbuffer(GL_RENDERBUFFER, rb);
	check_gl_error("make render_buffer");

EDIT : my call order is make_render_buffer() and then make_Fbo().

First of all, i would like to know how to print my depth buffer attachement form fbo for debug reasons.

Then I honestly think this code looks to simple to do what I want If you have any guidance to give me it will be a pleasure.


First of all, i would like to know how to print my depth buffer attachement form fbo for debug reasons.

You use glReadPixels to read the data in it. That’s the only way to read from a renderbuffer (in OpenGL).

Hi, I used it and it looks like my depth buffer is correct.
Thank you for your help :slight_smile:

But now a new issue appears to me.

The following Quotes comme from " fast triangle rasterization using
irregular z-buffer on cuda " wich is an article published in 2010.

Textures or render buffers can be attached onto the depth
attachment point of FBOs to accommodate the depth values. However, as far as
we have tested, they cannot be accessed by CUDA kernels.

Is this still true ?

we managed to use the color attachment points on the FBO. Apparently
in this case we have to write a simple shader program to dump the depth values onto
the color channels of the frame buffer. According to the GLSL specification [KBR06],
the special variable gl_FragCoord"

Does anyone used already this strategy ? is this not a more simple day nowadays to do that ?

Thank you for your help, feel free to comment or to give me ideas about a new strategy or about the one
presented in the article.