How to render color texture and depth texture at same pass?

Hi all,

I try to implement two textures adding with depth test.

But I encounter a problem.

I need to generate depth and color texture when I draw scene.

I create one Frame Buffer Object and bind color texture to COLOR_ATTACHMENT0 and depth texture to DEPTH_ATTACHMENT.

But it doesn’t work.
//------------------ Pesudo Code
//---- initialize
My texture parameter setting is :
glBindTexture(GL_TEXTURE_2D,depth_tex_id);

texture_param.SetMagFilterMode(TextureMagFilterModeList::LINEAR);
texture_param.SetMinFilterMode(TextureMinFilterModeList::LINEAR);
texture_param.SetTexCoordSAxisWrapMode(TextureWarpModeList::CLAMP_TO_EDGE);
texture_param.SetTexCoordTAxisWrapMode(TextureWarpModeList::CLAMP_TO_EDGE);
texture_param.SetTextureComparedMode(TextureComparedModeList::NONE);
texture_param.SetTextureComparedFunction(ComparedFunctionList::LEQUAL);
texture_param.SetTextureDepthTextureMode(TextureDepthTextureModeList::INTENSITY);

    glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,w,h,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_SHORT,0);

    glBindTexture(GL_TEXTURE_2D,color_tex_id);
    //......
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,w,h,0,GL_RGBA,GL_UNSIGNED_CHAR,0);

    glBindFrameBuffer(...);

    glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color_tex_id, 0); //level
    glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_tex_id, 0); //level

//---- rendering
glBindFrameBuffer(…);
clear depth and color
DrawScene();
glBindFrameBuffer(GL_FRAME_BUFFER,0);

Thanks.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.