can i read back the data inside a FBO?

hello everyone,

i want to implement a color based selection feature. so i first give each object a unique color, and then i render the region under the mouse selection into a buffer and check the color of pixels to determine which object is selected.

one option of implementing this is through glReadPixels. but i don’t want to use it, because it reads from the frame buffer, which means i need to use frame buffer for the selection rendering and then restore my normal rendering back.

better if there is an off-screen rendering method, so that i don’t need to interrupt the current frame buffer.

i know frame buffer object is useful for off-screen rendering, but normally it is for generating textures. it seems that the frame buffer object is always bind with texture maps when used. i have never seen a code sample that reads the data back from a fbo.

pbuffer is said to be deprecated. so i don’t want to use that either.

so what should i do?


glReadPixels can read out non-multisampled FBO’s, too. No problem here. And don’t worry, reading out that single or few pixels is fast enough. If you don’t want to render into a texture, why don’t you just use a normal Renderbuffer?

glReadPixels reads from whatever framebuffer is bound to the GL_FRAMEBUFFER_READ binding (or, if you’re still for some reason using the old EXT_FBO stuff, the GL_FRAMEBUFFER binding). So if you bind the default framebuffer, then you read from the default framebuffer. If you bind an FBO, then you read from the FBO.