tags:

views:

128

answers:

1

I'm trying to load a depthbuffer from a file and copy it to the depth buffer instead of clearing it every frame.

anyway, i'm a bit new to opengl, so i just tried to load my texture like this:

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, DepthData);

and i try to draw it like this:

glBindTexture(GL_TEXTURE_2D, DepthTexture);
glColorMask(FALSE, FALSE, FALSE, FALSE);

glBegin(GL_QUADS);

    glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f);

glEnd();

i tried to load a depthbuffer with every value set to 1.0, and everything i tried to draw got hidden, while it shouldn't.

what should i do? btw, i do NOT want to use glDrawPixels

+2  A: 

You are indeed drawing a textured quad that is not updating the color buffer and is still updating the depth buffer. However, the values you are writing are the actual depth values of the polygons, and not the values found in the texture! That's why everything ends up being z-culled.

The easiest way to accomplish what you want is to use a custom shader and write a custom gl_FragDepth value reading it from your texture.

UncleZeiv
The problem is that i can't use a shader, i'm gonna port it to open GL ES when it's finished (yes, i know about the glBegin/End, but that's not a big problem)
Brammie
@Brammie If you're using OpenGLES I don't think you have any choice but use `glDrawPixels`. Even with ES 2.0 you can't write depth from a shader (it's missing the `gl_FragDepth` output)
Andreas Brinck
@Andresa Brinck: wasn't glDrawPixels not supported? well.. i'll try it then.
Brammie