Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL depth buffer to texture (for various image sizes)
    primarykey
    data
    text
    <p>I'm having a problem with the depth buffer. I want to put into a texture. But it doesn't seem to work.</p> <p>So, here's the piece of code I execute after rendering the objects:</p> <pre><code> glGenTextures(1, (GLuint*)&amp;_depthTexture); glBindTexture(GL_TEXTURE_2D, _depthTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); const pair&lt;int, int&gt; &amp;img_size = getImageSize(); glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, img_size.first, img_size.second, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, img_size.first, img_size.second); glClear( GL_DEPTH_BUFFER_BIT ); </code></pre> <p>The thing is (I'm with OpenGL 3.2+), the image for rendering has different size. Most of the time, it won't be a 2^i by 2^j for the size. So, is that a problem ?</p> <p>Also, the other part of the problem might be in the fragment shader after:</p> <pre><code>#version 140 uniform sampler2D depthTexture; uniform ivec2 screenSize; out vec4 outColor; void main() { vec2 depthCoord = gl_FragCoord.xy / screenSize.xy; float d = texture2D(depthTexture, depthCoord).x; outColor = vec4(d, d, d, 1.0); } </code></pre> <p>After that, when I render a second time some shapes, I want to use the previous depth (the texture depth buffer), to do some effects.</p> <p>But seriously... can anyone just show me a piece of code where you can get the depth buffer into a texture? I don't care if it's rendering to the texture or if the texture is extracted after the rendering! As long as I have a texture with the depth value to do the second pass... that's what is important!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload