Hi
What’s the best way to use a (texture configured as a) depth buffer as an actual texture? Preferably without having to write a shader!
I tried just binding and using, but I get a uniform grey rectangle.
Cheers
IA
Hi
What’s the best way to use a (texture configured as a) depth buffer as an actual texture? Preferably without having to write a shader!
I tried just binding and using, but I get a uniform grey rectangle.
Cheers
IA
I use a depth texture attached to the depth attachment of a framebuffer object directly as a texture in my app, and it works.
Make sure you’re disabling GL_TEXTURE_COMPARE_MODE if it’s used as a shadowmap normally.
Maybe show us the faulty code?
GL gl = view.getGL ();
GLU glu = view.getGLU ();
/* 2D setup */
gl.glPushAttrib( GL_ALL_ATTRIB_BITS );
gl.glPushClientAttrib( (int)GL_CLIENT_ALL_ATTRIB_BITS );
gl.glDisable( GL_LIGHTING );
gl.glDisable( GL_DEPTH_TEST );
gl.glDepthMask( false );
gl.glMatrixMode( GL_PROJECTION );
gl.glPushMatrix();
gl.glLoadIdentity();
int width = view.getDrawable().getWidth();
int height = view.getDrawable().getHeight();
glu.gluOrtho2D( 0, width, 0, height );
gl.glEnable( GL_TEXTURE_2D );
gl.glMatrixMode( GL_MODELVIEW );
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glDisable( GL_TEXTURE_COMPARE_MODE );
/* Render */
int depthBufferID = frameBuffer.getDepthBufferID();
gl.glBindTexture( GL_TEXTURE_2D, depthBufferID );
gl.glBegin( GL_QUADS );
//gl.glColor3f( 1.0f, 0.0f, 0.0f );
gl.glTexCoord2f( 0.0f, 0.0f );
gl.glVertex2f( 0, 0 );
//gl.glColor3f( 0.0f, 1.0f, 0.0f );
gl.glTexCoord2f( 1.0f, 0.0f );
gl.glVertex2f( 256, 0 );
//gl.glColor3f( 0.0f, 0.0f, 1.0f );
gl.glTexCoord2f( 1.0f, 1.0f );
gl.glVertex2f( 256, 256 );
//gl.glColor3f( 1.0f, 1.0f, 0.0f );
gl.glTexCoord2f( 0.0f, 1.0f );
gl.glVertex2f( 0, 256 );
gl.glEnd();
/* 2D teardown */
gl.glMatrixMode( GL_PROJECTION );
gl.glPopMatrix();
gl.glMatrixMode( GL_MODELVIEW );
gl.glPopMatrix();
gl.glDepthMask( true );
gl.glEnable( GL_DEPTH_TEST );
gl.glPopClientAttrib();
gl.glPopAttrib();
I don’t think glDisable will work here. Here’s what I use :
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE);
Also a “gl.glColor4f(1, 1, 1, 1);” might help.
Bah, I went ahead and wrote a CG shader, which was an education for me. Works nicely now (though I’d still like to know what was missing from the above ??? )