Sign in to follow this  
Osaic

Simple full-screen quad texture rendering

Recommended Posts

Hi,

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 130
precision 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 130
precision 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!

Share this post


Link to post
Share on other sites
Hmmm.. did you check that you disabled alpha testing and alpha blending ? Then your error could be, that your texture has none or a zero alpha channel.

Share this post


Link to post
Share on other sites
Hi,

I am sorry to push this up again, but it still doesn't work.

I disabled alpha and depth testing and also set the alpha value in the shader manually to 1.0.

It is very strange that I get these errors, as they have worked in the past in other projects.

I haven't said that, but I am using OpenGL 3.2 Core Profile, GLSL 1.50, GLEW and GLFW

Share this post


Link to post
Share on other sites
Ok, I just solved this problem.

I was using GL_LINEAR_MIPMAP_LINEAR where I shouldn't.

Now everything is fine.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this