Jump to content
  • Advertisement
Sign in to follow this  
teexit

OpenGL Depth_Stencil texture in pixel shader

This topic is 2868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!