NikolajThorsen

Members
  • Content count

    4
  • Joined

  • Last visited

Community Reputation

150 Neutral

About NikolajThorsen

  • Rank
    Newbie
  1. Heres a good article thats among one of those i found very useful when I implemented my deferred rendering engine: http://www.beyond3d.com/content/articles/19/1
  2. OpenGL Display stencil part of GL_DEPTH24_STENCIL8_EXT

    Yes, i have used a similar solution, but this doesn't use the built-in GL_DEPTH24_STENCIL8_EXT. Having a separate color buffer just for stencil information seems very unnecessary. What is the correct way of getting the stencil part of GL_DEPTH24_STENCIL8_EXT, if i wish to display the stencil buffer on screen? If i have omitted any important details of my implementation, please tell me and ill give more information.
  3. First off, id like to thank anyone reading and/or replying to this first thread of mine. I have previous found help in others problems/solutions from this site, but i have been unable to find any help regarding my specific problem. So here i go with my own post. Im working on a deferred rendering engine at the moment, and i have multiple render targets. Along with storing positions, normals and diffuse color, i want one of these render targets to be used to store the depth and stencil values. Heres the code i use to create the texture: [CODE] .. glGenTextures(1, &depth_stencil_buffer); glBindTexture(GL_TEXTURE_2D, depth_stencil_buffer); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, width, height, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, NULL); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D , depth_stencil_buffer, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D , depth_stencil_buffer, 0); .. [/CODE] Now i can bind this texture, depth_stencil_buffer in the above code snippet, and render it on a fullscreen quad, and i can correctly see depth of the scene geometry. Heres the not so special code: [CODE] .. glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,depth_stencil_buffer); glUniform1i(glGetUniformLocation(m_uiTextureProgram, "tex"),0); glBindVertexArray(m_ui_texture_VAO); glDrawArrays(GL_TRIANGLES, 0,6); glBindVertexArray(0); glUseProgram(0); .. [/CODE] And my GLSL shader code looks something like this: [CODE] in vec2 tex_c; out vec4 output0; uniform sampler2D tex; void main() { output0 = texture(tex,tex_c); } [/CODE] Using this code its possible for me to display and observe the depth buffer. However, if I wish to render the stencil part of the texture, all i get is a white screen. I enable stencil testing, and even with a call to glClearStencil(0), which i think should turn the screen black instead of white, i still see only white tho. The way i try to render the stencil buffer, is by grabbing the .w coordinate (which should be the last 8bit containing stencil value) of the depth/stencil texture in the shader, and outputting just this value to screen. Heres the shader code that i use for this: [CODE] in vec2 tex_c; out vec4 output0; uniform sampler2D tex; void main() { output0 = vec4(texture(tex,tex_c).w); } [/CODE] I read in some OpenGL documentation (something i only vaguely remember), that if .w coordinate is missing (like if its only a vec3), getting .w in a shader always results in the value 1.0f. Could this be whats happening? This is btw not the only way if tried to render the stencil buffer to screen. But i have yet to find a working solution. Any and all help is appreciated! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]