This is really freaking cool, and I've been messing about with it for a short while now, but I have run across something very curious:

I have my test object which is normally drawn as a glutSolidSphere in the color blue. This is done at every cycle, while my picking function is done ONLY when the mouse is pressed. Tested a glutSolidSphere with 10 slices and 10 stacks for normal rendering and 16 slices and 16 stacks for picking rendering. That worked great and I was sold on the technique. But then I started doing some more in-depth testing and found something odd:

If I draw the spheres as 10 slices and 10 stacks for BOTH drawing functions, my pixel data returns blue at full alpha; the ORIGINAL drawing color. In fact, if I use anything equal to or less than the number of slices and stacks for both drawing sequences, my glReadPixels function returns the original blue color instead of the object's true ID color.

What's interesting is I also tried this with just a simple quad, and I cannot get it to work no matter the change in drawing size or method of the picking function. What's even more interesting is I used the glutSolidSphere to draw my picking shape in place of the quads, and the damned thing worked.

I'm at a total loss of even attempting to understand what is happening here. Is it possible that OGL is not allowing me to write over pixels that are already drawn in the normal draw function?

I tried glClear(GL_COLOR_BUFFER_BIT); before doing the picking drawing, but it doesn't change anything. Can anyone please help me, this is driving me mad! Thanks in advance!

Mac users swear by their computers, PC users swear at their computers. ~Unknown

Could it be that the depth test prevents your drawing to the selection buffer?
Having more slices/stacks on your sphere would render faces more close to the surface that would then succeed the depth test...

If this is the case, symply clearing the depth buffer should solve your problem

Pixels you draw for object IDs are still just pixels to OpenGL. They'll go through whatever pipeline you've left set up. That means, for example, if you've left depth testing enabled, those pixels will be tested against the depth buffer value created by the real object.

arekkusu Wrote:Pixels you draw for object IDs are still just pixels to OpenGL. They'll go through whatever pipeline you've left set up. That means, for example, if you've left depth testing enabled, those pixels will be tested against the depth buffer value created by the real object.

Do you think that's the issue? I'm going to try turning off depth testing and get back to you. Thanks for the idea!

Mac users swear by their computers, PC users swear at their computers. ~Unknown

arekkusu Wrote:Don't forget to use OpenGL Profiler's ability to show you the back/alpha/depth buffer after any draw command. Visualizing your data at any point helps to understand what's going on.

To be honest, I had considered depth testing to be an issue, but dismissed it as a possible issue because it didn't make any sense that something being drawn at the exact same position would not pass depth testing. Thanks for the tip, I will have to familiarize myself with the OpenGL Profiler. Thanks again!

Mac users swear by their computers, PC users swear at their computers. ~Unknown