Results 1 to 2 of 2

Thread: glReadPixels returns GL_INVALID_OPERATION

  1. #1

    glReadPixels returns GL_INVALID_OPERATION

    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!

  2. #2

    Re: glReadPixels returns GL_INVALID_OPERATION

    Well, found the answer for this, I had to specify the pixel alignment,

    glPixelStorei(GL_PACK_ALIGNMENT, 1);

Similar Threads

  1. glReadPixels too slow
    By e7fendy in forum OpenGL ES 2X - for programmable 3D graphics pipelines
    Replies: 1
    Last Post: 09-05-2011, 02:01 PM
  2. glReadPixels just returns 0s in Android.
    By as32b in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 07-18-2010, 11:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •