Android OpenGL ES read texture pixels
<p>The preview from my camera is rendered to a texture. I have the textureId and am trying to render the texture on a <code>FBO</code> so I can <code>glReadPixels</code>.</p>

<p>When I do actually read the pixels, all of them appear to be black though.</p>

<p>This is the code I am using at the moment:</p>

<pre><code>//called when the camera first connects to the texture
public void initBackBuffer()
    {
  // For use in getFramePixels()
        intBuffer = ByteBuffer.allocateDirect(width *
            height * 4)
            .order(ByteOrder.nativeOrder())
            .asIntBuffer();
        IntBuffer framebuffer = IntBuffer.allocate(1);
        glGenFramebuffers(1, framebuffer);
        glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get(0));
        int status = glGetError();
        if(status != GL_NO_ERROR)
        {
            Log.e("RENDERER", status + "");
        }

        IntBuffer depthBufferName = IntBuffer.allocate(1);

        glGenRenderbuffers(1, depthBufferName);
        glBindRenderbuffer(GL_RENDERBUFFER, depthBufferName.get(0));
        glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
                depthBufferName.get(0));
       glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
                mTangoCameraTexture.getTextureId(), 0);
        mOffscreenBuffer = framebuffer.get(0);
        status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

        if(status != GL_FRAMEBUFFER_COMPLETE) {
            if(status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)
                Log.e("RENDERER","GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
            if(status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)
                Log.e("RENDERER", "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT");
            Log.e("RENDERER", "FRAMEBUFFER ERROR:"+status);

        }
        glBindFramebuffer( GL_FRAMEBUFFER, 0 );

    }
// called onFrameAvailable
public void getFramePixels() {
    glBindFramebuffer(GL_FRAMEBUFFER, mOffscreenBuffer);
    int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if(status != GL_FRAMEBUFFER_COMPLETE)
    {
        Log.e(TAG, "FRAMEBUFFER STATUS:"+status);
    }
    glReadPixels(0, 0, width, height, GL_RGBA,
            GL_UNSIGNED_BYTE,
            intBuffer.clear());
    StringBuilder str = new StringBuilder();
    for(int i = 0; i &lt; intBuffer.capacity(); i++)
    {
        str.append(intBuffer.get(););
    }
    Log.d(TAG, "IMAGE:" + str.toString());
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

}
</code></pre>

<p>If I display the texture on the screen, I am able to see it - so the texture not being actually bound to the camera is excluded.</p>

<p><strong>Edit:</strong> there's a <code>GL_INVALID_OPERATION</code> happening at <code>glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D, getTextureId(), 0);</code> for some reason.</p>

<p>From the docs:</p>

<blockquote>
  <p>GL_INVALID_OPERATION is generated if zero is bound to target.
  GL_INVALID_OPERATION is generated if textarget and texture are not compatible.</p>
</blockquote>

<p>My <code>textureId</code> is <code>1</code>.</p>