Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: glReadPixels

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Location
    New Hampshrie
    Posts
    5

    Question glReadPixels

    Hi all -

    What I need to do is make a thumbnail of an opengl window image for when the window is not the foregroud window. I have it being rendered to the back buffer because if I do a SwapBuffers the image I want is there and in the bottom left corner and in the size I need. But glReadPixels just does not seem to work.

    I am not concerned about performance issues at this time. When the window is not the foreground window the image will be fairly static. I just need to put a thumbnail up in a different window.

    Thanks.

    - Brian

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,213
    What's not working when you try using glReadPixels? Can you post some code?

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2011
    Location
    New Hampshrie
    Posts
    5
    It just comes out gray. I can post the source code tomorrow. Sorry about the cross post.

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2011
    Location
    New Hampshrie
    Posts
    5
    Heres the relevant code snippets ...

    void C3DRender::RenderToBitmap(void *bits)
    {
    // without FBO
    // render to the backbuffer and copy the backbuffer to a texture

    // clear buffer
    glClearColor(1, 1, 1, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushAttrib(GL_COLOR_BUFFER_BIT | GL_PIXEL_MODE_BIT); // for GL_DRAW_BUFFER and GL_READ_BUFFER
    glDrawBuffer(GL_BACK);
    glReadBuffer(GL_BACK);

    // draw a rotating teapot at the origin
    glPushMatrix();

    // Draw here
    SetSize(280, 210);
    oglDrawScene();
    glFlush();
    // copy the frame buffer pixels to our bitmap
    glReadPixels(0, 0, 280, 210, GL_RGBA, GL_UNSIGNED_BYTE, bits);
    GLenum error = glGetError();
    SetSize(m_cx, m_cy);

    glPopMatrix();

    // copy the framebuffer pixels to a texture

    glPopAttrib(); // GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
    //SwapBuffers(hScreendc);
    }

    It gets called from this code snippet ...

    HBITMAP small_bitmap;
    void *bits = malloc(280 * 210 * 4);
    pRender->RenderToBitmap(bits);
    small_bitmap = CreateBitmap(280, 210, 1, 24, bits);
    m_wndDro.m_VideoWindow.SetBitmap(small_bitmap);
    //free(bits);


    Last edited by NewOpenGlProgrammer; 09-05-2012 at 09:54 AM.

Tags for this Thread

Posting Permissions

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