Depth_Stencil texture in pixel shader

Started by
-1 comments, last by teexit 13 years, 4 months ago
Hi, everyone.
I have a problem with depth_stencil texture.

I use OpenGL and store the depth_stencil in texture.

I set the FBO with these code (setting depth_stencil texutre)
glGenTextures(1,&depth_stencil_tex);glBindTexture(m_target,depth_stencil_tex);glTexParameteri(m_target, GL_TEXTURE_MAX_LEVEL , 1);glTexParameteri(m_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1);glTexParameteri(m_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);glTexParameteri(m_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);glTexParameteri(m_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);glTexParameteri(m_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);glTexImage2D(m_target, 0, GL_DEPTH24_STENCIL8_EXT, m_width, m_height, 0,                GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, NULL);glGenerateMipmapEXT(GL_TEXTURE_2D);		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fb); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,			GL_DEPTH_ATTACHMENT_EXT, m_target, depth_stencil_tex, 0);glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,			GL_STENCIL_ATTACHMENT_EXT, m_target, depth_stencil_tex, 0);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fb);


I first draw a model, and enable the stencil test and depth test. (I draw this to FBO)
glEnable(GL_DEPTH_TEST);glClearDepth(1.0f);glEnable(GL_STENCIL_TEST);glClearStencil(0);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);glClearColor(0,0,0,0);glStencilFunc(GL_ALWAYS, 1, 1);glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);glCallList(this->mModel["Head_Model"].mDisplayID);glDisable(GL_STENCIL_TEST);


and, I use the pixel shader to fetch the depth_stencil texutre.
If the texture's alpha value is 1, then output the red color.

I problem is...
I use 1 to mark the model which project on screen.
and, I except the ourput image is the model shape.
Result is not my except, all screen is red.

I don't know what happened...

How can I fix it?

Thanks a lot.

This topic is closed to new replies.

Advertisement