Reputation: 321
I am using a QOpenGLWidget and in the paintGL() method I am rendering a given texture to the screen. For the moment I am just loading images and render them to the screen. Everything is fine with that.
But now i want to do an offscreen rendering. I want to render into a frame buffer to do some calculations and store these calculation into the texture of that framebuffer. Than I want to render the result, so the texture of that frame buffer on to the screen with the existing rendering call.
For the moment I am just testing. So the rendering operation to the frame buffer is just coloring the hole screen in one color:
/* vertex shader */
#version 330
layout (location = 0) in vec3 a_position;
void main(void)
{
gl_Position = vec4(a_position, 1.0);
}
/* fragment shader */
#version 330
out vec3 fragColor;
void main(void)
{
fragColor = vec3(1.0,0.0,0.0);
}
The rendering call is also straight forward:
/* Render call */
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glClearColor(0.0,0.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(_vao);
glUseProgram(_program);
glDrawArrays(GL_TRIANGLES, 0, 3);
The VAO is just a simple square, and the same as I am using for the rendering to the screen. As we can see I am not rendering the full square, because I am only rendering 3 vertices.
My result is, that that one triangle is blue, the color I am clearing the frame buffer with and the other triangle is black, the one i am rendering. But this triangle should be red.
I normally don't have problems with using famebuffer and I am using them quit often. But this is the first time I am working with QT and my guess is, that there is something working differently while working with QT and frame buffers but I do not find a solution.
I am also adding the build of the frame buffer:
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _frameSize, _frameSize, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
//Error check
GLenum error = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (error == GL_FRAMEBUFFER_COMPLETE) {
std::cout << "FBO successfully loadet" << std::endl;
}else{
std::cout << "FBO had en ERROR !!!!!!!!!!!!!!!" << std::endl;
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
Upvotes: 1
Views: 497
Reputation: 321
Ok I found the problem .... I was binding my GLSL program with program.bind() and program is of typ QOpenGLShaderProgram.
And because for my frame buffer a am using only the Program ID of the program and i am binding with glUseProgram(program) it is somehow not not binding the program.
I don't know why it is not bounding the new program with glUseProgram(_program). But now I am binding the GLSL program the same why like the other shader and now it works ... I am sitting long time now on this problem :(
Upvotes: 1