View Full Version : Colorbuffer alpha value doesnt get cleared

Andreas K
07-08-2010, 02:33 AM

when I do

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);


and I read the buffer afterwards with glReadPixels() I get 0xFF as alpha value. The value I get is:

00 00 00 FF .... for each pixel.

How can I clear the FF also?


Dan Bartlett
07-08-2010, 03:42 AM
Does your buffer have an alpha channel? If it doesn't, then the specification states that the alpha value obtained should 1.0. Alpha bits can be queried with

glGetIntegerv(GL_ALPHA_BITS, &AlphaBits); //deprecated
or by querying an FBO with

glGetFramebufferAttachmentParameteriv( GL_READ_FRAMEBUFFER,
// or when default framebuffer is bound:
//glGetFramebufferAttachmentParameteriv( GL_READ_FRAMEBUFFER, GL_BACK_LEFT,
If you have 0 alpha bits returned, then you'd need to make sure that you create a buffer/attachment that contains an alpha channel.

Otherwise, have you changed the default color write mask anywhere? This would disable drawing to the alpha channel at all, including clearing


Andreas K
07-08-2010, 05:40 AM
Thanks a lot for your quick reply!

glGetIntegerv(GL_ALPHA_BITS, &AlphaBits); //deprecated

gives me 0. This means I do not have Alpha enabled. Also have no glColorMask.

So how do I enable Alpha for my buffer?

Thx, Andreas

07-08-2010, 06:32 AM
You enable alpha with the library you use to initialize your window.

For example, if you use glut, you have to pass GLUT_ALPHA to glutInitDisplayMode().

Andreas K
07-08-2010, 07:43 AM
Thanks u very much! I am using SDL and SDL_GL_SetAttribute() helped!!!