Simple setup, fbo with 2 textures which I want to render to the default framebuffer with blending. If I render one or the other texture, the screen renders what I would expect, including alpha transparency. But, if I try to render both one after another, only one (the first) of the two is rendered. My basic setup:
Simple shaders:
#version 450 core
layout (location = 0) in vec3 vert;
layout (location = 1) in vec2 texCoord;
out vec2 fTexCoord;
void main() {
fTexCoord = texCoord;
gl_Position = vec4(vert, 1);
}
#version 450 core
uniform sampler2D tex;
in vec2 fTexCoord;
out vec4 fColor;
void main() {
fColor = texture(tex, fTexCoord);
}
Assuming the handles corresponding to the input textures are tex1 and tex2, which I want to blend (and again render fine individually):
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glDepthMask(GL_TRUE); // Enable depth test (z-buffer)
glDepthFunc(GL_LESS); // z buffering
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// ...
// ... set up blend program
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex1);
blend_program->SetUniform("tex", 0);
glBindVertexArray(vao);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, render_indices);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, tex2);
blend_program->SetUniform("tex", 0);
glBindVertexArray(vao);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, render_indices);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
// unbind program