1

i am using a separate framebuffer object for color picking 2d objects in opengl. i am curious if its possible to only draw to the framebuffer and read the color when needed.

what i am doing now is in the main render loop i draw the scene to the main framebuffer and then render just the selectable objects to the "picking" framebuffer.

when the user clicks the mouse it binds the "picking" framebuffer and reads the pixel and i know which object is selected. the problem with this is i only need the "picking" framebuffer when a user clicks the mouse so doing this every frame is inefficient.

i have tried rendering to the "picking" framebuffer when the user clicks the mouse and then reading directly but all i get is white (the background color and not the color to tell me which object it is). drawing the "picking" framebuffer just shows the entire thing as white like nothing was actually rendered to it at all.

do i need to stop drawing in the main loop while rendering to the "picking" framebuffer? or is there something im missing that would make this possible?

EDIT: i have tried not drawing in the main loop while rendering to the picking framebuffer and that did not work either.

cuatro
  • 103
  • 2
  • 9
  • Do you `glFlush()` between your draw and your read? – genpfault Nov 04 '10 at 21:34
  • i do. im thinking the "No" answer might be the correct one. – cuatro Nov 04 '10 at 22:58
  • Are you doing that concurrently? – tibur Nov 04 '10 at 23:09
  • nope. ive tried every sequential way i know and the only one that works is when i render the picking fbo while i render the normal framebuffer, which isnt a huge deal on modern hardware (maybe 5%) but on older stuff it can be closer to a ~30-40% performance hit. – cuatro Nov 05 '10 at 03:10
  • If your not in a multi threaded app, and with only one context, that should work. Check why your FBO rendering has to be done just after normal rendering. (Matrices, Textures, ...) – tibur Nov 05 '10 at 10:22
  • yea ill mess around with it some more to see if i cant get it to work. – cuatro Nov 05 '10 at 14:36

2 Answers2

0

You need to check that you made your GL context the current one using either wglMakeCurrent or glXMakeCurrent. Also, it has to be done in the same thread, since only one thread can have a current context.

tibur
  • 11,531
  • 2
  • 37
  • 39
0

"No".

But you can multiple GPUs (if you have it). Here or here you can find the OpenGL specification; the driver must support *WGL_NV_gpu_affinity* or *AMD_gpu_association* extension.

Luca
  • 11,646
  • 11
  • 70
  • 125
  • That would prevent performance issue when rendering on *two* OpenGL context as the same time on different threads. But you need a professional GPU to access those extensions. – tibur Nov 04 '10 at 23:18