I want to render the depth buffer to a texture, and draw a quad with the DepthTexture. But it doesn't work.
First i make DepthTexture:
glGenTextures(1, &_iTexDepth);
glBindTexture(GL_TEXTURE_2D, _iTexDepth);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, _w, _h, 0,
GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);
and prepare to render:
glViewport(0, 0, _w, _h);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(camera_proj);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(camera_modelview);
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_PIXEL_MODE_BIT);
glDrawBuffer(GL_BACK);
glReadBuffer(GL_BACK);
glClearColor(0, 0, 0, 1);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
and render something, and copy to the texture:
glBindTexture(GL_TEXTURE_2D, _iTexDepth);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, _w, _h);
glBindTexture(GL_TEXTURE_2D, 0);
and last, i bind _iTexDepth and draw a Quad
This code works with GL_RGBA8 Texture well, but does not work with GL_DEPTH_COMPONENT (white only with DEPTH_COMPONENT)
If you have some idea about this problem, i want some help
P.S. I don't want to use FBO