tags:

views:

316

answers:

4

I'm attempting to visualize the depth buffer for debugging purposes, by drawing it on top of the actual rendering when a key is pressed. It's mostly working, but the resulting image appears to be zoomed in. (It's not just the original image, in an odd grayscale) Why is it not the same size as the color buffer?

This is what I'm using the view the depth buffer:

void get_gl_size(int &width, int &height)
{
    int iv[4];
    glGetIntegerv(GL_VIEWPORT, iv);
    width = iv[2];
    height = iv[3];
}

void visualize_depth_buffer()
{
    int width, height;

    get_gl_size(width, height);

    float *data = new float[width * height];

    glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, data);
    glDrawPixels(width, height, GL_LUMINANCE, GL_FLOAT, data);

    delete [] data;
}
A: 

That code ought to work. Do you by any chance have something else call glPixelZoom ? It's worth resetting it to check that you're not actually asking for a zoom.

Bahbar
+1  A: 

I'm not sure whether this is your actual error, but there's a few things that I can recommend you check. It would be nice if you actually provided a screenshot of how exactly it's zoomed in.

First off, make sure the projection/modelview matrices are exactly the same as your rendering. I can't see how it would affect it, but it would be something to look into.

Second, the spec specifies that glPixelStore, glPixelTransfer, and glPixelMap can affect the results, you would want to make sure that these are being set properly.

If you do end up getting this working, please share what went wrong - it seems an interesting question. :)

Andrei Krotkov
A: 

one more thing to check is that your raster position is correct. see glRasterPos. the code as posted should work, but i can see how state is screwed up elsewhere (you do draw something before visualizing depth...) that said, you are probably in an area of gl drivers that is not well tested because it is unusual. what you should do next: - test with a different vendor (ati/nv..) - write the read data to a file to see if drawing or reading is not working as expected

A: 

1) Dump the raw depth buffer data into a file.

2) Open it using IrfanView (Open as -> RAW file)

3) Adjust the parameters (width, height) and the pixel format according to your depth buffer BPP (8bits, 16bits, ...). Make sure the greyscale is checked.

4) Get a beer.

OrB