This is how i implemented my FBO in the scene manager constructor
glGenRenderbuffers(1, &RBO); // Generate one render buffer and store the ID in fbo_depth
glBindRenderbuffer(GL_RENDERBUFFER, RBO); // Bind the fbo_depth render buffer
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 1024, 780); // Set the render buffer storage to be a depth component, with a width and height of the window
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, RBO); // Set the render buffer of this buffer to the depth buffer
glBindRenderbuffer(GL_RENDERBUFFER, 0); // Unbind the render buffer
glGenTextures(1, &FBO_Texture); // Generate one texture
glBindTexture(GL_TEXTURE_2D, FBO_Texture); // Bind the texture fbo_texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 780, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); // Create a standard texture with the width and height of our window
// Setup the basic texture parameters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Unbind the texture
glBindTexture(GL_TEXTURE_2D, 0);
glGenFramebuffers(1, &FBO); // Generate one frame buffer and store the ID in fbo
glBindFramebuffer(GL_FRAMEBUFFER, FBO); // Bind our frame buffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, FBO_Texture, 0); // Attach the texture fbo_texture to the color buffer in our frame buffer
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, RBO); // Attach the depth buffer fbo_depth to our frame buffer
/*switch (glCheckFramebufferStatus(GL_FRAMEBUFFER)){
case GL_FRAMEBUFFER_COMPLETE:
std::cout << "Complete." << std::endl;
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
std::cout << "Incomplete Attachment" << std::endl;
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
std::cout << "Incomplete Missing Attachment" << std::endl;
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
std::cout << "Not all attached images have the same width and height." << std::endl;
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
std::cout << "Framebuffer Unsupported" << std::endl;
break;
}*/
glBindFramebuffer(GL_FRAMEBUFFER, 0);
this should be ok as i have used glCheckFramebufferStatus and it didnt return any errors.
now for the rendering. This is the draw call in my scene manager (which works fine if i remove the FBO so the error cant be in a diff place)
glViewport ( 0, 0, esContext->width, esContext->height );
// Clear the color buffer
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
for(int j=0; j<Resources->ShaderNum ; j++)
{
userData->programObject = Resources->Programs[j];
glUseProgram ( Resources->Programs[j] );
for(int i=0; i<ObjectsLoaded; i++)
{
if(GameObjects->shader == j+1)
{
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
if(Resources->Shaders[j].Culling && Culling == false)
{
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
Culling = true;
}
if(Resources->Shaders[j].Blending && Blending == false)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Blending = true;
}
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
GameObjects->Draw(esContext);
if(Culling == true)
{
glDisable(GL_CULL_FACE);
Culling = false;
}
if(Blending == true)
{
glDisable(GL_BLEND);
Blending = false;
}
}
}
}
eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
glBindFramebuffer(GL_FRAMEBUFFER, 0); // unbind
// Clear the color buffer
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
userData->programObject = Resources->PostProcessingPrograms[0];
Quad->Draw(esContext);
and this is what the post processing quad draw call looks like
GLfloat vVertices[] = { 512.0f, 390.0f, 0.0f,
-512.0f, 390.0f, 0.0f,
-512.0f, -390.0f, 0.0f,
512.0f, -390.0f, 0.0f};
GLfloat vTexCoord[] = { 1.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f};
// Use the program object
glUseProgram ( userData->programObject );
glBindAttribLocation ( userData->programObject, 0, "vPosition" );
glBindAttribLocation ( userData->programObject, 1, "a_texCoord" );
glActiveTexture(GL_TEXTURE0 + 1);
Texture_Uniform_Loc = glGetUniformLocation ( userData->programObject, "texture1" );
glBindTexture(GL_TEXTURE_2D, Scene->FBO_Texture);
glUniform1i(Texture_Uniform_Loc, 1);
// Load the vertex data
glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices );
glEnableVertexAttribArray ( 0 );
glVertexAttribPointer ( 1, 3, GL_FLOAT, GL_FALSE, 0, vTexCoord );
glEnableVertexAttribArray ( 1 );
glDrawArrays ( GL_TRIANGLES, 0, 3 );
eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
there are no errors but everything on the screen is just black.
i tried making the quad smaller reversing the vertex order (Clockwise and CounterClockwise) i tried using the perspective matrix and rotated around to try and find the quad in case i misplaced it but nothing works the screen just stays black. im pretty sure im simply not rendering to the FBO right or im not applying the texture to the quad right but im not sure what i did wrong.
Any help would be greatly appreciated.