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?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 374 |
Nodes: | 16 (2 / 14) |
Uptime: | 141:16:05 |
Calls: | 7,958 |
Calls today: | 3 |
Files: | 13,011 |
Messages: | 5,814,067 |