0

I've been searching around for hours and can't find a way to read pixel data from a texture in any format.

glReadPixels either returns all 0s or needs a texture to be rendered to the framebuffer (which also seems to be a mystical function with no real help on)

And every time I search for glTexImage2D for reading data, all the questions are about writing data

I've got more texture data being generated than I'd want to keep lying around in arrays for recall, so I'd rather just read back the pixels at a later point.

I wouldn't even mind an obscure format that's difficult to decode; just some way to get R, G, B and A from a texture that is currently being mapped onto an object.

Someone, please help me D:!!!

derhass
  • 43,833
  • 2
  • 57
  • 78
Rogod
  • 188
  • 1
  • 13
  • 1
    GLES lacks the `glGetTexImage` familiy of functions desktop GL has. – derhass Apr 13 '14 at 18:28
  • What about glReadPixels? Is there literally no way to get the texture data being drawn to the screen back? – Rogod Apr 13 '14 at 21:19
  • Sure. You can render a textured (fullscreen or whatever size you need, you framebuffer must be at least as big as the texture, obviously) quad and read that back. – derhass Apr 13 '14 at 21:52
  • But how? - I don't understand what that means? There seems to be no explanation as to what this "render texture to framebuffer" process entails :( If I can just figure that out, I should hopefully be able to use glReadPixels amIright? – Rogod Apr 13 '14 at 22:53
  • I didn't say "render texture to framebuffer" but I said "render a textured quad". I don't know what your current level of GL knowledge is, but the fact that you are using textures in the first place suggested to me that you should be aware of how to render textured primitives. – derhass Apr 13 '14 at 22:57
  • Sorry, the brackets confused me xD Rendering to quads is exactly what I'm doing. I can't get any texture data back with glReadPixels though. Every time I attempt it I get all 0s, no matter what pixel I choose. What is the proper procedure? - It feels like I'm just missing something silly like a permission or a draw-somewhere-else call first. – Rogod Apr 14 '14 at 07:33
  • show the relevant code parts. It is impossible to guess what is going on here. – derhass Apr 14 '14 at 20:53
  • The code is basically as follows: `ByteBuffer buffer=ByteBuffer.allocate(4); gl.glBindTexture(GL10.GL_TEXTURE_2D,texture); gl.glReadPixels((x*16)+z,y,1,1,GL10.GL_RGBA,GL10.GL_UNSIGNED_BYTE,buffer); byte[] rgb=buffer.array(); Col c=new Col(rgb[0],rgb[1],rgb[2],rgb[3]); return c;` Wherever I read the data (even just 0,0 on a texture loaded in at startup) I just get all 0s for the colour components. – Rogod Apr 14 '14 at 21:10
  • You are not rendering anything here. You really should look for some tutorials are other GL beginner resources. – derhass Apr 14 '14 at 21:28
  • `gl.glLoadIdentity(); ByteBuffer buffer=ByteBuffer.allocate(4); gl.glBindTexture(GL10.GL_TEXTURE_2D,texture); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glFrontFace(GL10.GL_CCW); gl.glTexCoordPointer(2,GL10.GL_FLOAT,0,tb); gl.glVertexPointer(3,GL10.GL_FLOAT,0,vb); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,0,quadV.length/3); gl.glReadPixels(1,1,1,1,GL10.GL_RGBA,GL10.GL_UNSIGNED_BYTE,buf); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);` – Rogod Apr 14 '14 at 21:30
  • Still no use. - I assumed glReadPixels would be able to read the texture without it being on screen? Either way doesn't work though. (Also I see no tutorials on writing and reading texture data. :( ) – Rogod Apr 14 '14 at 21:32
  • No, `glReadPixels` reads just what is in the framebuffer, it cannot read back textures. You also have to select the current `glReadBuffer`. You should btw not paste the code in the comments, but edit the question instead. – derhass Apr 14 '14 at 21:34
  • I've just tried using: `GLES30.glReadBuffer(GL10.GL_FRONT);` Just before the glReadPixels method, but it still returns all zeros when reading the top left corner. Even though I'm clearing the screen with (0.125f,0.25f,0.5f,1)RGBA. This all seems thoroughly complicated and/or unsupported - for something as trivial as reading data from a glorified array in VRAM. – Rogod Apr 14 '14 at 21:53
  • Aha! It was the mixture of examples and code snippets I've tried. I was reading to the ByteBuffer "buf" but extracting colour data from "buffer" - which remained empty. Sorry about all this - I'll post a solution for others when I've wormed my way through all my comments and lines. – Rogod Apr 14 '14 at 21:56

0 Answers0