Note that there are some explanatory texts on larger screens.

plurals
  1. POReading a openGL ES texture to a raw array
    primarykey
    data
    text
    <p>I'm trying to get the bytes from a RGBA texture in openGL ES. I think I'm trying to imitate <code>glGetTexImage</code> from vanilla openGL. As is right now, the pixels are all nil, from the call to <code>glClear</code>, not the texture data I'm looking for.</p> <p>This is a method in a category extending SPTexture from Sparrow Framework.</p> <pre><code>-(NSMutableData *) getPixelsFromTexture { GLsizei width = (GLsizei) self.width; GLsizei height = (GLsizei) self.height; GLint oldBind = 0; glGetIntegerv(GL_TEXTURE_BINDING_2D, &amp;oldBind); glBindTexture(GL_TEXTURE_2D, self.textureID); GLuint fbo[1]; glGenFramebuffersOES(1, fbo); glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo[0]); GLuint rbo[1]; glGenRenderbuffersOES(1, rbo); glBindRenderbufferOES(GL_RENDERBUFFER_OES, rbo[0]); glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA4_OES, width, height); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, rbo[0]); GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); if (status != GL_FRAMEBUFFER_COMPLETE_OES) { NSLog(@"Incomplete FBO"); } // draw static float texCoords[8] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }; static float vertexCoords[8] = { -1.0f, -1.0f, 1-.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f }; glMatrixMode (GL_PROJECTION); glPushMatrix(); glLoadIdentity (); glOrthof(0.0f, self.width, self.height, 0.0f, 0.0f, 1.0f); glMatrixMode (GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, texCoords); glVertexPointer(2, GL_FLOAT, 0, vertexCoords); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); // end draw GLsizei count = width * height * 4; GLubyte * pixels = (GLubyte *)malloc((sizeof(GLubyte) * count)); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); glBindRenderbufferOES(GL_RENDERBUFFER_OES, 0); glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); glBindTexture(GL_TEXTURE_2D, oldBind); glDeleteRenderbuffersOES(1, rbo); glDeleteFramebuffersOES(1, fbo); return [NSMutableData dataWithBytes:pixels length:count]; } </code></pre> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload