I’m trying to render a teapot to a Frame Buffer, but all i see is the clear color, i don’t see a teapot. I also checked the glGetError and glCheckFramebufferStatus(EXT), but they are all good. Anyone any idea what the problem could be??
This is my render function:
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); // Bind our frame buffer for rendering
glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); // Push our glEnable and glViewport states
glViewport(0, 0, window_width, window_height); // Set the size of the frame buffer view port
glClearColor (0.0f, 1.0f, 0.0f, 1.0f); // Set
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the depth and colour buffers
glLoadIdentity(); // Reset the modelview matrix
glTranslatef(0.0f, 0.0f, -5.0f); // Translate back 5 units
glRotatef(rotation_degree, 1.0f, 1.0f, 0.0f); // Rotate according to our rotation_degree value
// TEAPOT
glFrontFace(GL_CW);
glutSolidTeapot(1.0f); // Render a teapot
glFrontFace(GL_CCW);
// Then i'm reading all the pixels and pass that to another program
// which renders the result. But no teapot :-(
glReadPixels(0, 0, 1024, 768, GL_RGB, GL_UNSIGNED_BYTE, pixels);
glPopAttrib(); // Restore our glEnable and glViewport states
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // Unbind our texture
int r = glGetError(); // r = 0 -> OK
int s = glCheckFramebufferStatus(GL_FRAMEBUFFER); s = 36053 = OK
int sx = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); sx = 36053 = OK
[/b]
[/b]
I just thought that maybe i don’t need a FBO at all. I could just read everything from the back buffer too right? Well anyway, i tried it. But unfortunately all i get is a black screen (the clear color).
The thing is, is that i don’t need a glut window to draw to. Once i have the pixel information, then i pass that to another program which will draw the image for me.
My init function looks like this:
char fakeParam[] = "nothing";
char *fakeargv[] = { fakeParam, NULL };
int fakeargc = 1;
glutInit( &fakeargc, fakeargv );
GLenum err = glewInit();
if (GLEW_OK != err)
{
MessageBoxA(NULL, "Failed to initialize OpenGL", "ERROR", NULL);
}
else
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
// Not sure if this call is needed when i don't use a glut window to render too...
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
}
Then in my render function i do:
void DisplayFunc(void)
{
static float alpha = 0;
/* Clear the buffer, clear the matrix */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// TEAPOT
glTranslatef(0.0f, 0.0f, -5.0f); // Translate back 5 units
glRotatef(rotation_degree, 1.0f, 1.0f, 0.0f); // Rotate according to our rotation_degree value
glFrontFace(GL_CW);
glutSolidTeapot(1.0f); // Render a teapot
glFrontFace(GL_CCW);
glReadBuffer(GL_BACK);
glReadPixels(0, 0, (GLsizei)1024, (GLsizei)768, GL_RGB, GL_UNSIGNED_BYTE, pixels);
}
This is basically all i do. At the end of the last function is where i’m trying to read all the pixels. But the output is just a black image.
If the window isn’t visible, then all of its pixels fail the pixel-ownership test. Which means that reads from those pixels contain undefined data. IE: probably not what you rendered.
If your window is visible and not covered, you don’t have to worry about the pixel ownership problem. However, these days it is probably best to just go with the FBO solution in any case.