Bon il semblerait que le problème vienne de la SFML, j'ai essayé d'utiliser opengl en dehors de la SFML pour dessiner presque la même chose avec deux FBO et là le blending alpha se fait bien.
int main(int argc, char* argv[])
{
sf::Window window(sf::VideoMode(800, 600), "test", sf::Style::Default, sf::ContextSettings(0, 0, 4, 3, 0));
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
}
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
float verticesFBO1[] = {-1.f, -1.f,
1.f, 0, 0, 0.5f,
-0.90f, -1.f,
1.f, 0, 0, 0.5f,
-0.90f, -0.90f,
1.f, 0, 0, 0.5f,
-1.f, -0.90f,
1.f, 0, 0, 0.5f};
float verticesFBO2[] = {-0.95f, -0.95f,
0, 1.f, 0, 0.5f,
-0.85f, -0.95f,
0, 1.f, 0, 0.5f,
-0.85f, -0.85f,
0, 1.f, 0, 0.5f,
-0.95f, -0.85f,
0, 1.f, 0, 0.5f};
float fullScreenQuad[] = {-1.f, -1.f,
1.f, 1.f, 1.f, 1.f,
0.f, 0.f,
-1.f, 1.f,
1.f, 1.f, 1.f, 1.f,
1.f, 0.f,
1.f, 1.f,
1.f, 1.f, 1.f, 1.f,
1.f, 1.f,
1.f, -1.f,
1.f, 1.f, 1.f, 1.f,
0.f, 1.f};
GLuint textureFBO1;
glGenTextures(1, &textureFBO1);
glBindTexture(GL_TEXTURE_2D, textureFBO1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 800, 600, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
GLuint textureFBO2;
glCheck(glGenTextures(1, &textureFBO2));
glBindTexture(GL_TEXTURE_2D, textureFBO2);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 800, 600, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
const char* data = reinterpret_cast<const char*>(fullScreenQuad);
glVertexPointer(2, GL_FLOAT, 32, data + 0 );
glColorPointer(4, GL_FLOAT, 32, data + 8);
glTexCoordPointer(2, GL_FLOAT, 32, data + 24);
sf::Context contextFBO1(sf::ContextSettings(0, 0, 4, 3, 0),800, 600);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
const char* data2 = reinterpret_cast<const char*>(verticesFBO1);
glVertexPointer(2, GL_FLOAT, 24, data2 + 0 );
glColorPointer(4, GL_FLOAT, 24, data2 + 8);
GLuint framebuffer1;
glGenFramebuffers(1, &framebuffer1);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer1);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureFBO1, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
std::cerr<<"failed to create frame buffer 1";
}
sf::Context contextFBO2(sf::ContextSettings(0, 0, 4, 3, 0),800, 600);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
const char* data3 = reinterpret_cast<const char*>(verticesFBO2);
glVertexPointer(2, GL_FLOAT, 24, data3 + 0 );
glColorPointer(4, GL_FLOAT, 24, data3 + 8);
GLuint framebuffer2;
glGenFramebuffers(1, &framebuffer2);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer2);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureFBO2, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
std::cerr<<"failed to create frame buffer 2";
}
fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
contextFBO1.setActive(true);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_QUADS, 0, 4);
glFlush();
contextFBO2.setActive(true);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_QUADS, 0, 4);
glFlush();
window.setActive(true);
glClear(GL_COLOR_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, textureFBO1);
glDrawArrays(GL_QUADS, 0, 4);
glBindTexture(GL_TEXTURE_2D, textureFBO2);
glDrawArrays(GL_QUADS, 0, 4);
window.display();
}
return 0;
}