I'm still trying to read pixels from the fragment shader, and I have some questions. I know that gl_FragColor is returning with vec4, which means RGBA, 4 channels. After that, I use glReadPixels to read the FBO and write it to the data
GLubyte *pixels = new GLubyte[640*480*4];
glReadPixels(0, 0, 640,480, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
This works great, but it's actually a speed issue. Instead, I want to just read RGB to ignore alpha channels. I tried:
GLubyte *pixels = new GLubyte[640*480*3];
glReadPixels(0, 0, 640,480, GL_RGB, GL_UNSIGNED_BYTE, pixels);
and it didn’t work. I guess, because gl_FragColor returns 4 channels, and maybe I should do something before that? In fact, since my returned image (gl_FragColor) has shades of gray, I did something like
float gray = 0.5
gl_FragColor = vec4(gray,gray,gray,1.0);
So, is there an efficient way to use glReadPixels instead of using the first 4 channel method? Any suggestion? By the way, this is opengl es 2.0 code.