• Picking using glReadPixels & glBindFramebuffer

    From redhog.org@gmail.com@21:1/5 to All on Thu Aug 9 10:18:39 2018
    I'm trying to implement picking using a framebuffer generated using glGenFramebuffers, but glReadPixels returns invalid enum whenever I have called glBindFramebuffer():


    Picking code:

    int data[4];
    glBindFramebuffer(GL_FRAMEBUFFER, picking_fb);
    draw_scene();
    glReadPixels(x, height - y, 1, 1,
    GL_RGBA, GL_INT,
    (GLvoid *) data);

    What combinations of type and format works with what texture format? I would like to use a non-byte format, as I need to fit more data per pixel than 4 bytes...


    Code to generate the FB

    glGenTextures(1, &color_tex);
    glBindTexture(GL_TEXTURE_2D, color_tex);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, overlay_attr.width, overlay_attr.height, 0, GL_RGBA, GL_FLOAT, NULL);
    glGenFramebuffers(1, &picking_fb);
    glBindFramebuffer(GL_FRAMEBUFFER, picking_fb);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color_tex, 0);
    glGenRenderbuffers(1, &depth_rb);
    glBindRenderbuffer(GL_RENDERBUFFER, depth_rb);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 256, 256);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_rb);
    glBindFramebuffer(GL_FRAMEBUFFER, picking_fb);

    Any ideas?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From zhuyuanxuan@gmail.com@21:1/5 to All on Wed Aug 22 19:18:42 2018
    On Friday, August 10, 2018 at 1:18:41 AM UTC+8, Egil Möller wrote:
    I'm trying to implement picking using a framebuffer generated using glGenFramebuffers, but glReadPixels returns invalid enum whenever I have called glBindFramebuffer():


    Picking code:

    int data[4];
    glBindFramebuffer(GL_FRAMEBUFFER, picking_fb);
    draw_scene();
    glReadPixels(x, height - y, 1, 1,
    GL_RGBA, GL_INT,
    (GLvoid *) data);

    What combinations of type and format works with what texture format? I would like to use a non-byte format, as I need to fit more data per pixel than 4 bytes...


    Code to generate the FB

    glGenTextures(1, &color_tex);
    glBindTexture(GL_TEXTURE_2D, color_tex);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, overlay_attr.width, overlay_attr.height, 0, GL_RGBA, GL_FLOAT, NULL);
    glGenFramebuffers(1, &picking_fb);
    glBindFramebuffer(GL_FRAMEBUFFER, picking_fb);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color_tex, 0);
    glGenRenderbuffers(1, &depth_rb);
    glBindRenderbuffer(GL_RENDERBUFFER, depth_rb);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 256, 256);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_rb);
    glBindFramebuffer(GL_FRAMEBUFFER, picking_fb);

    Any ideas?

    GL_INT ? Try to check it maybe...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)