Screen Capture

I am trying to do a screen capture and write it to a jpeg file. My understanding is that the framebuffer will contain whats being rendered to the display and using PixelRead should grab whats in the framebuffer. What I am seeing is just a black image rather than whats rendered on the display.

GLubyte* pixelBuffer = new GLubyte[sizeof(GLubyte)*width*height*3];

GLint ReadBuffer;
GLint PackAlignment;
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixelBuffer);

Any ideas on what I am doing wrong? I am developing on a Dell Optiplex GX620 with an Intel 82945G/GZ graphics controller.

OpenGL Driver Info

Vendor: Tungsten Graphics, Inc
Version: 1.4 Mesa 7.1 rc1
Renderer: Mesa DRI Intel® 945G 20061102 x86/MMX/SSE2

Color Bits(R,G,B,A): (8, 8, 8, 8)
Depth Bits: 24
Stencil Bits: 8


The problem could be elsewhere, but if you want to debug it, just fill your buffer with some color, like white, to
see it it’s actually being overwritten. Also make sure your writing functions are working. Fill it with some known
color to see if it’s actually being written correctly.

memset( pixelBuffer, 0xFF, sizeof(GLubyte)widthheight*3 );

As you suggested, I filled my pixelbuffer with another color prior to the glReadPixels call, but still get the same result. Likewise,the writing function seem to be working correctly. I initialized this to a different color which was overwritten by the initialized color in pixelBuffer. So it seems pixelBuffer is not reading the framebuffer for some reason.

My video card does not support GL_ARB_pixel_buffer_objects, which should not matter for glPixelRead right? Or maybe my graphics card does not support openGL also? Guess I will try to find a system which I know supports openGL and run my code on that. Thanks for you suggestions.


oops bad thread… :smiley:

Hem,… I have a suggestion now:

Try in a first step to copy to framebuffer to a texture with glCopyTexImage2D and then clear the framebuffer and draw the last texture on a quad. This way you could check if your allocations, arrays, file writing,… are wrong or not.