Results 1 to 3 of 3

Thread: glDrawPixels equivalent - how to load a saved buffer

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    1

    glDrawPixels equivalent - how to load a saved buffer

    Hi everyone,
    I'm pretty new to OpenGL, and I'm making an iphone application where I need to save/load the screen contents; I'm saving with glReadPixels, and was hoping to use glDrawPixels to reload, but alas it doesn't exist. From googling the problem it seems that I need to load the saved buffer into a texture, and then write the texture to the screen, but I'm sort of lost as to how I would do this, and I really need some sample code to wrap my head around it. Can anyone help me out?

    Thanks!

  2. #2
    Junior Member
    Join Date
    Jun 2010
    Posts
    2

    Re: glDrawPixels equivalent - how to load a saved buffer

    You can use glTexSubImage2D to write the pixels back into a texture that has been previously created.

    Code :
    void setup()
    {
        glGenTextures(1, &textureId);
        // Allocate texture memory only (pass NULL for data)
        glTexImage2D(..., NULL);
    }
     
    void copySurfaceToTexture()
    {
        // Copy surface contents to 'data'
        glReadPixels(..., data);
     
        // Upload data into our texture
        glBindTexture(GL_TEXTURE_2D, textureId);
        glTexSubImage2D(..., data);
    }
    glReadPixels introduces a pipeline stall and is generally a slow operation, so make sure you need it.

    If it's available, eglBindTexImage is another way to render to texture (OpenGL ES 1.x + EGL 1.1), which may be more efficient.

    If you are using OpenGL ES 2.0, you can use framebuffer objects to render to texture, which is a much better alternative.

  3. #3
    Junior Member
    Join Date
    Jun 2010
    Posts
    1

    Re: glDrawPixels equivalent - how to load a saved buffer

    I will try this if this will work with mine, too.

    Anyhow, thanks and God bless,

Similar Threads

  1. Load texture via streaming from user space buffer
    By john_q61 in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 10-19-2010, 09:10 AM
  2. equivalent to glPushAttrib()
    By crischprolch in forum OpenGL ES general technical discussions
    Replies: 4
    Last Post: 06-30-2008, 09:22 AM

Posting Permissions

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