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 2 of 2

Thread: Problem with reading color buffer out.

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    15

    Question Problem with reading color buffer out.

    Dear all, I want to read the color buffer out using the following code. Unfortunately, I got a all-zero result result. Could somebody kindly review this code below? Thanks in advance.

    void showFrameBufferImage()
    {
    static int index = 0;
    int nextIndex = 0;

    index = (index + 1) % 2;
    nextIndex = (index + 1) % 2;

    const int glViewportWidth_ = osuCGDeskConfig_->windowWidth_, glViewportHeight_ = osuCGDeskConfig_->windowHeight_;
    const int DATA_SIZE = glViewportWidth_ * glViewportHeight_ * 4;

    framebufferImage_ = cv::Mat(glViewportHeight_, glViewportWidth_, cv:ataType<cv::Vec3f>::type);

    glGenBuffers(2, PBO_);
    glBindBuffer(GL_PIXEL_PACK_BUFFER, PBO_[index]);
    glBufferData(GL_PIXEL_PACK_BUFFER, DATA_SIZE, 0, GL_STREAM_READ);
    glBindBuffer(GL_PIXEL_PACK_BUFFER, PBO_[nextIndex]);
    glBufferData(GL_PIXEL_PACK_BUFFER, DATA_SIZE, 0, GL_STREAM_READ);

    glReadBuffer(GL_FRONT);

    glBindBuffer(GL_PIXEL_PACK_BUFFER, PBO_[index]);
    glReadPixels(0, 0, glViewportWidth_, glViewportHeight_, GL_RGBA, GL_UNSIGNED_BYTE, 0);

    // map the PBO that contain framebuffer pixels before processing it
    glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, PBO_[nextIndex]);
    GLubyte* src_ = (GLubyte*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);

    if(src_)
    {
    cv::Vec3f vec_;

    for(int i = 0; i < glViewportHeight_; i++)
    for(int j = 0; j < glViewportWidth_; j++)
    {
    vec_[0] = *(src_)/255.0;
    vec_[1] = *(++src_)/255.0;
    vec_[2] = *(++src_)/255.0;

    framebufferImage_.at<cv::Vec3f>(glViewportHeight_-1-i, j) = vec_;

    ++src_; //// skip alpha
    }

    glUnmapBuffer(GL_PIXEL_PACK_BUFFER); // release pointer to the mapped buffer
    }

    glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
    glDeleteBuffers(2, PBO_);
    }

  2. #2
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    15
    Please ignore this post; I gave up using pixel buffer objects and turned to rendering buffer objects.

Posting Permissions

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