Texture not changed in the fragment shader.


#1

Hi, I need to change the texture of my FS but when I set the texture parameter :


Texture tmpDepthBufferTexture = Texture(depthBuffer.getTexture());
                Texture tmpStencilBufferTexture = Texture (stencilBuffer.getStencilTexture());
                depthBuffer.clear(sf::Color::Transparent);
                stencilBuffer.clear(sf::Color::Transparent);
                frameBufferGenerator.setParameter("haveTexture", 1);
                for (unsigned int i = 0; i < m_instances.size(); i++) {
                    currentStates.texture = &tmpStencilBufferTexture;
                    stencilBuffer.draw(m_instances[i].getAllVertices(),currentStates);
                    frameBufferGenerator.setParameter("depthBuffer", tmpDepthBufferTexture);
                    depthBuffer.draw(m_instances[i].getAllVertices(),currentStates);
                }

The texture is not changed so it’s the cleared one which is referenced in my FS.


const std::string frameBufferGenFragShader =
                "#version 130 
"
                "uniform sampler2D depthBuffer;"
                "uniform sampler2D texture;"
                "uniform vec3 resolution;"
                "uniform float haveTexture;"
                "in mat4 projMat;"
                "void main () {"
                    "vec2 position = ( gl_FragCoord.xy / resolution.xy );"
                    "float max_z = texture2D(depthBuffer, position).z;"
                    "vec4 texel = texture2D(texture, gl_TexCoord[0].xy);"
                    "vec4 colors[2];"
                    "colors[1] = texel * gl_Color;"
                    "colors[0] = gl_Color;"
                    "bool b = (haveTexture > 0.9);"
                    "vec4 color = colors[int(b)];"
                    "float z = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;"
                    "colors[1] = color;"
                    "colors[0] = vec4(0, 0, 0, 0);"
                    "b = (z < max_z);"
                    "gl_FragColor = colors[int(b)];"
                "}";


#2

OpenGL gets me an error : (parameter depthBuffer not found in shader)

But HE IS IN THE SHADER.


#3

I give up with this, opengl is full of bugs.


#4

[QUOTE=laurent7601;1293570]OpenGL gets me an error : (parameter depthBuffer not found in shader)

But HE IS IN THE SHADER.[/QUOTE]

It might be in your code, that does not mean it is in the shader. If you define a variable A and write something like that:

gl_FragColor = vec4(1,1,1, 1 - A*0);

A would never end up being in the shader, since it does not contribute to the final result (A*0 is always 0 regardless what it stored in A) and is therefore optimized out! So check you operation flow of all variables that depend on “depthBuffer” and if it’s contribution to that variables will have any effect on the final result. The OpenGL error suggests that you have done something that removes its influence on the frag color. So check every instruction and maybe visualize the result values.

I give up with this, opengl is full of bugs.

You not understanding how OpenGL works is not a bug.


#5

[QUOTE=laurent7601;1293570]OpenGL gets me an error : (parameter depthBuffer not found in shader)

But HE IS IN THE SHADER.[/QUOTE]

It might be in your code, that does not mean it is in the shader. If you define a variable A and write something like that:

gl_FragColor = vec4(1,1,1, 1 - A*0);

A would never end up being in the shader, since it does not contribute to the final result (A*0 is always 0 regardless what it stored in A) and is therefore optimized out! So check you operation flow of all variables that depend on “depthBuffer” and if it’s contribution to that variables will have any effect on the final result. The OpenGL error suggests that you have done something that removes its influence on the frag color. So check every instruction and maybe visualize the result values.


I give up with this, opengl is full of bugs. 

Not understanding how OpenGL works is not a bug.