1
votes

I am using OpenGL ES 2.0 and GLSL to draw objects. Then I want to read pixel from whatever my fragment shader draws on my screen. I am blending two grayscale textures and at the end of my fragment shader, I have:

gl_FragColor = vec4(something...blending textures);

I know that gl_FragColor means the final color will be written in the frame buffer. (According to http://nehe.gamedev.net/article/glsl_an_introduction/25007/) Given that, I did something like

GLubyte *pixels = new GLubyte[320*240];
glReadPixels(0, 0, 320,240, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels);

After drawing image using that, at the first, I get same as the original texture1 and then get the black empty color. Can someone help me what's wrong? Do I need to do something with FBO? I am a kinda lost...:(

1
I suppose that after glReadPixels you update one of your textures that is input to the shader in the next frame? Post some more code how you update the texture, maybe the error is there.Ville Krumlinde
Please show us code from your program, those lines are untelling.datenwolf

1 Answers

3
votes

Per the canonical ES 2.0 documentation for glReadPixels, the format parameter:

Specifies the format of the pixel data. The following symbolic values are accepted: GL_ALPHA, GL_RGB, and GL_RGBA.

So GL_LUMINANCE is not a supported read format in GL ES.

Beyond that, assuming you have a working frame buffer of some sort and you're applying your fragment shader by rendering a suitably placed piece of geometry to the frame buffer, glReadPixels should be the correct thing to use.