Hi,

I am trying to render onto a texture and attach this texture as color attachment for FBO object in Android platform using Open GL ES 2.0 library. Following is the code snippet,

/* Create a texture to render into */
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);

/* Crreate an FBO */
glGenFramebuffers(1, &m_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);

/* Attach texture as color attachment to FBO */
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0);
glBindTexture(GL_TEXTURE_2D, 0);

Then I draw onto FBO using glDraw commands. I see that all draw commands get executed successfully. However, when I call glReadPixels (to take the screen shot of rendered image) later, it return GL_INVALID_OPERATION,

unsigned char *pixels = (unsigned char *)malloc(width*height*4);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, pixels);
GLint error = glGetError(); // error gets set to 0x502

Any clue why is this call getting failed? Please help!