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)];"
"}";