hi! i want to render the depth information of a scene into a texture, but it results in a plain white texture. am i missing sth obvious?
on initialization:
glGenTextures( 1, &m_uiDepthId );
glBindTexture( GL_TEXTURE_2D, m_uiDepthId );
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f );
while rendering:
//Save viewport
int avViewport[4];
glGetIntegerv( GL_VIEWPORT, (int*)avViewport );
//Set new viewport
glViewport( 0, 0, 512, 512 );
// Render models
for( unsigned int CurrentModel = 0; CurrentModel < m_vModels.size(); CurrentModel++ )
m_vModels[CurrentModel]->Render();
// Save in depth texture
glBindTexture( GL_TEXTURE_2D, m_uiDepthId );
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 512, 512, 0 );
// Reset viewport
glViewport( avViewport[0], avViewport[1], avViewport[2], avViewport[3] )
zed
2
most depth vals will be high thus looking white,
increase the z near distance 100 or 1000x
Humus
3
Or do something like pow(depth, 50.0) when visualizing it.
Try it with an FBO.
Setting things up:
unsigned int fbo;
unsigned int tex;
unsigned int tex_res = 256;
// Prepare Texture.
glGenTexture( 1, &tex );
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, tex_res, tex_res, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
// Prepare Fbo.
glGenFramebuffersEXT( 1, &fbo );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbo );
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, tex, 0 );
glDrawBuffer( GL_FALSE );
glReadBuffer( GL_FALSE );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
// Render Loop.
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbo );
glPushAttrib( GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT );
glViewport( 0, 0, tex_res, tex_res );
glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
glDepthMask( GL_TRUE );
// DRAW SOMETHING!.
glPopAttrib();
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );