Discussion:
Picking using glReadPixels & glBindFramebuffer
(too old to reply)
r***@gmail.com
2018-08-09 17:18:39 UTC
Permalink
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?
z***@gmail.com
2018-08-23 02:18:42 UTC
Permalink
Post by r***@gmail.com
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...

Loading...