我遇到这个问题,glReadPixels不会读取颜色附件。
我想做什么:
阅读非默认帧缓冲区的第三色附件(下面的代码)
glFlush();
glFinish();
//binds my fbo with state GL_FRAMEBUFFER
RENDER_MANAGER.DeferredBuffer->bind();
unsigned char data[4];
glPixelStorei(GL_PACK_ALIGNMENT, 1);
unsigned int check = glGetError();
glReadBuffer(GL_COLOR_ATTACHMENT3);
glReadPixels(e->p->x, e->p->y, 1, 1,GL_RGB, GL_UNSIGNED_BYTE, data);
什么有效:
glBindFramebuffer(GL_FRAMEBUFFER,_FBO);
/////create depth texture
glGenTextures(1, &_colorAttacherment[index]);
glBindTexture(GL_TEXTURE_2D, _colorAttacherment[index]);
glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, width, height);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
////bind texture to the fbo
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_TEXTURE_2D, _colorAttacherment[index], 0);
glBindFramebuffer(GL_FRAMEBUFFER, GL_NONE);
我的具体问题是让glReadPixels读取颜色附件。
答案 0 :(得分:0)
这里可能适用的随机想法: 所有平台都不支持GL_RGB与glReadPixels一起使用。如果支持,请检查GL_IMPLEMENTATION_COLOR_READ_FORMAT。