Background:
I am trying to draw primitives into the default window-system framebuffer object. I have three objects which correctly get rendered. Now, I want to generate my own framebuffer object to contain these same images, but have each object rendered in a flat unique color ID to be used for selection during run-time. The user will be presented with three objects, will select one of the objects by a mouse click, then the code will read a pixel in the framebuffer object to determine the color. Once the color has been read, the color of the object will be changed to indicate that it has been selected.
Problem:
For some reason, glBindFramebuffer(GL_FRAMEBUFFER, fbo);
is giving me a GL_INCOMPLETE_DRAW_BUFFER
after a call to glCheckFramebufferStatus(GL_FRAMEBUFFER)
. The code is attached. Maybe I'm not setting the framebuffer object up correctly? Or, maybe VMWare doesn't allow framebuffer objects? I would like to have some sanity check to ensure this is the correct way of doing framebuffer objects.
Code (hopefully just the relevant parts):
void initFrameBuffers()
{
glGenRenderbuffers(NumRBOs, rbos);
glBindRenderbuffer(GL_RENDERBUFFER, rbos[COLOR]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, WIDTH, HEIGHT);
glBindRenderbuffer(GL_RENDERBUFFER, rbos[DEPTH]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, WIDTH, HEIGHT);
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Causes the error
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbos[COLOR]);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbos[DEPTH]);
glEnable(GL_DEPTH_TEST);
// Re-enable the default window-system framebuffer for drawing
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
void drawToFBO()
{
// Load the user defined framebuffer object
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glViewport(0, 0, WIDTH, HEIGHT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Draw into the user defined framebuffer object, not the default window-system FBO
glBindVertexArray(vaos[CYLINDER]);
glDrawArrays(GL_TRIANGLES, 0, cylinder.vertices.size());
// Re-enable the default window-system framebuffer
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
Now, I'm not sure if I need to do anything special before I call my initFrameBuffers method, but this is what I'm doing. My main function just makes a call to initFrameBuffers
, then calls my init()
method, which draws three objects into the default window-system FBO.
I have tried this same code in a newer version of Kubuntu, and it gives me a different error code: GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
instead of GL_INCOMPLETE_DRAW_BUFFER
. I'm definitely not sure on what is going on here. I'm reading through the red book eighth edition, and am following what they suggest, but cannot seem to get past getting my framebuffer to bind.