glReadPixels doesn't work anymore

Hi !

I want to save the screen content - what already worked. but now i added some other things and now i have the following problem:

when i call “glReadPixels” to get the content of the framebuffer, it does NOTHING.
It generates no error, but doesn’t read anything in the array.

My application is single-buffered, and glReadPixels reads from the default color buffer (GL_FRONT_LEFT).

i have absolutely no idea because it doesn’t worke anymore



Would you please write the line where you call glReadPixels ?

Also, what OS/graphics card/driver do you have ?

The lines:
// window_x_, window_y_ … size of (glut-created) window
GLubyte* img_buf = new GLubyte [3 * window_x_ * window_y_];
glReadPixels (0, 0, window_x_, window_y_, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*) img_buf);

I use Windows 98. Graphic-Card: ATI Rage Mobility. I link against Opengl32, glu32, glut32 - libraries (i think these are the one from SGI).
I had to turn “hardware accelerating” off because otherwise the os crashed periodly when i debugged my opengl-program.

The strang thing is that ‘glReadPixels’ already worked fine. Then i added some features to my program and now glReadPixels does nothing.

Two things :

  • please call glGetString(GL_VENDOR), glGetString(GL_RENDERER) and glGetString(GL_VERSION) and post here the results. Because turning hardware acceleration to off may switch your engine to software rendering (and those calls will show that),
  • now that you added a few lines of code, do you call glPixelStore, glPixelTransfer or glPixelMap ?

hi !

glReadPixels did work also after i turned off the hardware acceleration.

The Output from the glGets() is:

Microsoft Corporation
GDI Generic

My PixelStore-Commands are:
(I dont know if i need all of them)

glPixelStorei( GL_PACK_ROW_LENGTH, window_x_ );
glPixelStorei( GL_PACK_SKIP_ROWS, 0 );
glPixelStorei( GL_PACK_SKIP_PIXELS, 0 );
glPixelStorei( GL_PACK_ALIGNMENT, 1 );

glPixelStorei( GL_PACK_SKIP_ROWS, 0 );
glPixelStorei( GL_PACK_SKIP_PIXELS, 0 );
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

I have no glPixelMap - Commands in the program

The Output from the glGets() is:

             Microsoft Corporation
             GDI Generic

you’re running the software renderer. Expect bad performance.

Did you add some of those glPixelStore commands between the time glReadPixels worked and between the time glReadPixels did not work ?

I have no glPixelMap - Commands in the program

I’m assuming you don’t call glPixelTransfer either, right ?

you are right.

NO glPixelTransfer - commands.

Also, what do you mean by “it does NOTHING” ? Does your buffer remains unchanged ? Is it filled by zeros only ? Are the colors messed up ?

it doesn’t change the buffer content.

in fact, i can pass a NULL-pointer to glReadPixels and it doesn’t complain.

OpenGL specifies that if an error is generated, the buffer is not modified.
Have you called glGetError() just after glReadPixels ?

of course i call glGetError after.
it reports no error.

You could try a few things:

try GL_RGBA instead of RGB
try calling glFinish() right after ReadPixels
make sure the width and height parameter are positive

otherwise, it probably is just buggy drivers. That card is pretty much obsolete and is no longer supported.


now it works !

i turned the hardware acceleration on - now i can read the pixels.

it seems to be a problem of the software rendering / driver.

thanks for the helpful comments,