frame buffer objects render to depth render buffer

hotgolem

Newcomer
Hi all,

For creating a shadow map I've set up a depth render buffer object, using
this code:

GLuint frameBuffer = 0;
GLuint renderBuffer = 0;

glGenFramebuffersEXT(1, &frameBuffer);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffer);

// Render depth values to a buffer.
glGenRenderbuffersEXT(1, &renderBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24,
width, height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, renderBuffer);

glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);

// Check validity of the frame buffer and go back to traditional
rendering if something failed.
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
canUseFBOs = false;

This works fine so far but now I want to get the depth values into a memory
buffer to make it a nice look looking, smooth shadow (blurring it,
adjusting alpha values and such). Later I want to take the result and use
this as texture for a simple quad. The problem I have is the glReadPixels
call, which throws an access violation in the ATI driver. It looks so:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

render(1);

void* buffer = malloc(3 * width * height);
glReadBuffer(GL_DEPTH_ATTACHMENT_EXT);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer);

What is it that I'm doing wrong here? It doesn't really look complicated to
read the pixels. I have already done this with the color attachment (to
save to a file), but reading the depth values causes trouble.

I should maybe add that I want to implement a cheap drop shadow for my scene objects. The scene is entirely 2D with a white background "paper" (+ grid) and a lot of arbitrarily formed objects laying around. I have no OpenGL lighting and don't need an expensive shadow creation (shadow volumes etc.). All I want to do is to render the object in question into an FBO (depth only to get the silouette) and create a shadow texture.

Thank you,

Mike
 
I think you should use something like this :
glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, buffer);
and remove this line :
glReadBuffer(GL_DEPTH_ATTACHMENT_EXT);

GL_DEPTH_ATTACHMENT_EXT is not a valid enum for glReadBuffer
 
Back
Top