ReadPixels not saving alpha value.

I’m trying to get glReadPixels to read the alpha values of the framebuffer but I keep getting only RGB values. The alpha value is set to 255 always.

BufferedImage frameImage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);


gl.glReadPixels(0, 0, frameImage.getWidth(), frameImage.getHeight(),
GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, db.getData());

Can anybody tell me what I’m doing wrong.

Did you use a GLCapabilities with a non-zero number of alpha bits?

Also the alpha channel appears to not be supported by e.g. Microsoft’s GDI OpenGL rasterizer and some other software (pixmap-based) renderers.

Look at the JGears source code for an example of reading back the color and alpha channels.

I use canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
which dumps as:

GLCapabilities [DoubleBuffered: true, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 0, Red: 8, Green: 8, Blue: 8, Alpha: 0, Red Accum: 0, Green Accum: 0, Blue Accum: 0, Alpha Accum: 0 ]

It was the alpha setting of the GLCapabilities. it was set to 0 by default. Thanks.