开发者

glReadPixels and alpha channels returning 1.0

开发者 https://www.devze.com 2023-02-05 02:19 出处:网络
I\'m reading pixel data from a framebuffer, and everything seems to work, except for the alpha value, which is always 1.0

I'm reading pixel data from a framebuffer, and everything seems to work, except for the alpha value, which is always 1.0

  GLfloat lebuf[areasize * 4];
  glReadPixels(xstart, ystart, partw, parth, GL_RGBA, GL_FLOAT, lebuf);

I've set the window creation code to support an alpha channel:

  SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);

Is there any other place I should look at for checking why the alpha channel seems to be 1.0 all the time? Better yet, is there another way (other than glReadPixels) to get the texture into client memory, f开发者_开发知识库rom the framebuffer?

edit: this is how I clear the buffer:

 glClearColor(0,0,0,0);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


Could you check:

  • That you SDL has accepted your format (glGetIntegerv(GL_ALPHA_BITS, bits))?
  • That your color clear is not 1 (glClearColor). What if you clear to 0.5 and retrieve the buffer before rendering. Do you retrieve 0.5?
  • That you alpha buffer is not write locked (glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE))?
  • That you correctly clear your alpha buffer at the end of each frame?
  • That your blend function will write the correct alpha value to the buffer?


If you are using GLUT, remember you have to set your main window as follows:

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL);

otherwise glReadPixels will read always alpha channel = 1.


Please use the following line.. problem will solved.

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号