This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

OPENGL ES2.0 issue with glReadPixels

Hi

I am trying to a sample OpenGL ES code which just draws a triangle on screen. I need to read back the display buffer content, so I used glreadpixels. But it is always filling my buffers with  zeros. I have referred to http://processors.wiki.ti.com/index.php/Render_to_Texture_with_OpenGL_ES.                                                                                

I am not rendering to any FBO. I am using the window system created framebuffer and default GL_COLOR_ATTACHMENT0.

My render code looks like this:

glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays ( GL_TRIANGLES, 0, 3 );
glReadPixels(0, 0, width,height, GL_RGB,GL_UNSIGNED_BYTE,pixels);
eglSwapBuffers(gl.display, gl.surface);


My fragment shader :

void main()                                  
{                                            
    gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );
    
} 

My vertex shader

void main()                  
{                            
   gl_Position = vPosition;  
}  

with the following vertices:

GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f };

My rendering is working properly.

Why is glReadPixel always filling buffer with zeros?.

Thanks & Regards

Thushara