Is there a way to get the FBO pixel data and then: greyscale it fast and take back the image to that FBO again?
1 Answers
If you're using the fixed-function pipeline (ES 1.1), you can use glReadPixels
to pull pixel data off the GPU so you can process it directly. Then you'd need to create a texture from that result, and render a quad mapped to the new texture. But this is a fairly inefficient way of accomplishing the result.
If you're using shaders (ES 2.0), you can do this on the GPU directly, which is faster. That means doing the greyscaling in a fragment shader in one of a few ways:
If your rendering is simple to begin with, you can add the greyscale math in your normal fragment shader, and perhaps toggle it with a boolean uniform variable.
If you don't want to mess with greyscale in your normal pipeline, you can render normally to an offscreen FBO (texture), and then render the contents of that texture to the screen's FBO using a special greyscale texturing shader that does the math on sampled texels.
Here's the greyscale math if you need it: https://web.archive.org/web/20141230145627/http://bobpowell.net/grayscale.aspx Essentially, plug the RGB values into that formula, and use the resulting luminance value in all your channels.

- 24,203
- 9
- 60
- 84

- 70,108
- 23
- 141
- 204
-
Thanks but glReadPixels is not an option, because that is very slow and laggy. :( Any other in fixed pipeline? – lacas Aug 02 '12 at 10:38
-
@lacas: Without shaders, the only other way to do it is to actually render the screen in greyscale to begin with. You'd need to probably ask a separate question with more details about your scene (2d? 3d? lighting? etc) to get savvy answers about how to approach that, but in theory you could modulate all of your colors so that you were only coloring in greys. – Ben Zotto Aug 02 '12 at 14:13