This one is for the OpenGL savvies.
I’m trying to read pixels from an FBO and I want to understand why this does not work:
ofPixels pix;
// allocate pix to match fbo
fbo.bind();
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); // <- This is because I'm working with PBOs, probably irrelevant
glReadPixels(0, 0, width, height, format, GL_UNSIGNED_BYTE, pix.getPixels());
fbo.unbind();
While this does:
fbo.readToPixels(pix);
The first option gives me an access violation
[…]
Actually, this makes it work:
glPixelStorei(GL_PACK_ALIGNMENT, 4); // <--- Needed, why?
fbo.bind();
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glReadPixels(0, 0, width, height, format, GL_UNSIGNED_BYTE, pix.getPixels());
fbo.unbind();
The glPixelStorei call is made within ofFbo::readToPixels, why is this call necessary?
Also, why is glGetTexImage
preferred to glReadPixels
when TARGET_OPENGLES
is undefined?