I am having this problem where glReadPixels won't read color attachments.
What I am trying to do:
Read 3rd color attachment of non-default framebuffer(Code below)
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);
What works:
- Framebuffer and all color attachments work
- I tested the 3rd color attachment by rendering it to the back buffer and displaying that to screen.
- if I glReadPixels after I render colorattachment to front buffer it works as intended
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);
My specific problem is getting glReadPixels to read a color attachment.