Hi, I have some problems with Listing 18.4 and 18.5 they are on the pages 619-621.
I can compile the project but when it starts I get that the function glCheckFramebufferStatusEXT doesn’t return GL_FRAMEBUFFER_COMPLETE_EXT. There are two framebuffers and I get the same error for both of them. I also get that glGetError isn’t equal to GL_NO_ERROR. The entire source code is copied from the books source code. Any ideas?
Here is the code:
// ==== GLOBAL ============================================
GLboolean doProcessing = GL_TRUE;
GLuint framebufferID[2];
// ==== IN SETUP FUNCTION =================================
// Set up some renderbuffer state
glGenRenderbuffersEXT(1, &renderbufferID);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderbufferID);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT32, fboWidth, fboHeight);
glGenFramebuffersEXT(2, framebufferID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[0]);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, renderbufferID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, renderTextureID[0], 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[1]);
for (int i = 0; i < maxDrawBuffers; i++)
{
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + i, GL_TEXTURE_2D, renderTextureID[i+1], 0);
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
// ==== RENDER FUNCTION =====================================
if (doProcessing)
{
// draw the scene as pass 1 to an FBO
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[0]);
glViewport(0, 0, fboWidth, fboHeight);
GLenum fboStatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (fboStatus != GL_FRAMEBUFFER_COMPLETE_EXT)
{
fprintf(stderr, "FBO #1 Error!
");
}
}
else
{
// just draw the scene to the window
glViewport(0, 0, windowWidth, windowHeight);
}
...
if (doProcessing)
{
GLint uniformLoc;
int loopCount;
// 2nd pass: Redraw from texture w/ fragment shader outputting to multiple targets
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[1]);
}
...
if (useDrawBuffers)
{
// single shader will write to all 4 render textures simultaneously
loopCount = 1;
GLenum buf[4] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT};
glDrawBuffers(maxDrawBuffers, buf);
}
else
{
// we need a separate shader pass for each render target
loopCount = maxDrawBuffers;
}
while (loopCount--)
{
...
GLenum fboStatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (fboStatus != GL_FRAMEBUFFER_COMPLETE_EXT)
{
fprintf(stderr, "FBO #2 Error!
");
}
}
...
// 3rd pass: Tile the multiple targets back to the window
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glViewport(0, 0, windowWidth, windowHeight);
...
if (glGetError() != GL_NO_ERROR)
fprintf(stderr, "GL Error!
");