I want to read the pixels from the back buffer. But all i get so far 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:
// No main function, so no real argv argc
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 since 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)
{
/* 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);
int r = glGetError();
}
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. glGetError() doesn’t give any errors.
Anyone any idea what the problem could be…???
It doesn’t work like that. The backbuffer is not some kind of off-screen rendering area, it’s part of on-screen window. Actually the whole doublebuffer concept only makes sense for on-screen windows. Each pixel of a double buffered window has two color values, but only one depth, stencil, etc.; upon buffer swap just the pointer to the back and front pixel plane are exchanged. But because we’re still talking about a window, when rasterizing all fragments go through the pixel ownership test, i.e. are checked for, if they are actually visible on screen. If not, they’re not rendered.
But your problems go further: You don’t even create a window, so you don’t have an OpenGL context at all. Your calling of OpenGL commands has no effect whatsoever. glReadPixels doesn’t return you anything, because there’s nothing to read from.
The bad news is, that the only way to get a context with GLUT is, by creating a window. The good news is, you don’t have to use GLUT. People, why don’t you get this: GLUT is not part of OpenGL, it’s a quick and dirty framework for writing small tutorials, nothing more.
What you want is either:
or