I thought I am past these beginner problems, but I am obviously not. I cannot render a simple full-screen quad with a texture.It just stays black.
I am first rendering the scene to a framebuffer object with a texture (called imgScene in my code) for post-processing.
For now, I want to render just the texture.
C++ code to render (fullquad_t contains 4 glm::vec2 elements with the different -1/1 values)
void render(void) { glBindFramebuffer(GL_FRAMEBUFFER, fbo); renderScene(); glBindFramebuffer(GL_FRAMEBUFFER, 0); displayScene(); glfwSwapBuffers();}void displayScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(hImageShaderProgram); glDisable(GL_DEPTH_TEST); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, imgScene); GLint uFBOTexture = glGetUniformLocation(hImageShaderProgram, "fbo_texture"); GLint aTexCoords = glGetAttribLocation(hImageShaderProgram, "texCoords"); glUniform1i(uFBOTexture, 0); glEnableVertexAttribArray(aTexCoords); glVertexAttribPointer(aTexCoords, 2, GL_FLOAT, GL_FALSE, 0, fullquad_t); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, fullquad_i); glDisableVertexAttribArray(aTexCoords); glBindTexture(GL_TEXTURE_2D, 0); glEnable(GL_DEPTH_TEST); glUseProgram(0);}
Vertex Shader
#version 130precision mediump float;const madd = vec2(0.5, 0.5);in vec2 texCoords;out vec2 tex_coord;void main() { tex_coord = texCoords.xy * madd + madd; gl_Position = vec4(texCoords.xy, 0.0, 1.0);}
Fragment Shader
#version 130precision mediump float;uniform sampler2D fbo_texture;in vec2 tex_coord;out vec4 fragColor;void main() { fragColor = texture2D(fbo_texture, tex_coord);}
I tested if the tex_coord param is handed through correctly, and it is (rendering a gradient if using it as color params). I also tested if the rendered FBO texture is black but it is not, but contains the correct image (with gDEBugger).
So the problem seems to be the texture.
Thank you in advance, for helping me!