Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>glReadPixels</strong> function reads from framebuffers, not textures. To read a texture object you must use <strong>glGetTexImage</strong> but <strong>it isn't available in OpenGL ES</strong> :(</p> <p>If you want to read the buffer from your texture then <strong>you can bind it to an FBO (FrameBuffer Object) and use glReadPixels</strong>:</p> <pre><code>//Generate a new FBO. It will contain your texture. glGenFramebuffersOES(1, &amp;offscreen_framebuffer); glBindFramebufferOES(GL_FRAMEBUFFER_OES, offscreen_framebuffer); //Create the texture glGenTextures(1, &amp;my_texture); glBindTexture(GL_TEXTURE_2D, my_texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //Bind the texture to your FBO glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, my_texture, 0); //Test if everything failed GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); if(status != GL_FRAMEBUFFER_COMPLETE_OES) { printf("failed to make complete framebuffer object %x", status); } </code></pre> <p>Then, you only must call to glReadPixels when you want to read from your texture:</p> <pre><code>//Bind the FBO glBindFramebufferOES(GL_FRAMEBUFFER_OES, offscreen_framebuffer); // set the viewport as the FBO won't be the same dimension as the screen glViewport(0, 0, width, height); GLubyte* pixels = (GLubyte*) malloc(width * height * sizeof(GLubyte) * 4); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); //Bind your main FBO again glBindFramebufferOES(GL_FRAMEBUFFER_OES, screen_framebuffer); // set the viewport as the FBO won't be the same dimension as the screen glViewport(0, 0, screen_width, screen_height); </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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