can't pick out alpha value in frame buffer

hi,everyone
i have codes like this:

// set back color
glClearColor(0.0,0.0,0.0,0.0);

glColor4f(0.6,0.6,0.6,0.5);
// draw something


glFinish();
// now we want to get the pixels in frame buffer
glReadPixels(0,0,win_sizex,win_sizey,GL_RGBA,
GL_UNSIGNED_BYTE,pixel_buf);

code is finished,but whatever we set the params in glColor4f, the alpha value stored in
the pixel_buf is always 1.0, so how can i properly get the alpha value in the frame buffer?

thanks!!!

You need to make certain that your window is supplying an alpha channel. This is done in the Windows pixelformat definition or in GLUT you need to specify GLUT_RGBA and GLUT_ALPHA when you create your window.

Try doing this:

GLint alpha_bits;
glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);

after you create your rendering context to verify that you are getting a pixel format that has alpha.

yes! just check the pixelformat,
I use glut, so I set GLUT_ALPHA when
glutInitDisplayMode,it runs good.
thanks!