OpenGL Color Buffer Overwrite

Member
Posts: 215
Joined: 2008.06
Post: #1
First of all, Merry Christmas.

Secondly, I've been taking a look at this interesting article for object selection in 3D: http://gpwiki.org/index.php/OpenGL_Selec..._Color_IDs

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

iSayz
Quote this message in a reply
Apprentice
Posts: 8
Joined: 2008.12
Post: #2
Hi Talyn,

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 Wink
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #3
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.
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #4
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

iSayz
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #5
Talyn Wrote: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!

That seems to be the trick! I will have to do some more testing, but it's behaving a lot better now! Thanks arekkusu!!

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

iSayz
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #6
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.
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #7
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

iSayz
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2008.12
Post: #8
Depth testing is done per-fragment (per-pixel) not per polygon or per glutSolidSphere for that matter. Why not use the selection buffer as described on the same wiki?

http://gpwiki.org/index.php/OpenGL:Tutorials:Picking
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2008.12
Post: #9
Selection buffer on the Iphone ? Not possible right ?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Pixel Buffer Object setup issue dotbianry 2 3,359 Jan 6, 2013 11:03 AM
Last Post: dotbianry
  iPhone OpenGL color bug agreendev 8 7,439 Aug 12, 2010 08:20 PM
Last Post: AnotherJake
  ? Find color value of 'pixel' in color buffer? Elphaba 1 4,547 Jul 22, 2009 01:23 PM
Last Post: Bachus
  OpenGL Texture from Char* Buffer gradyeightythree 0 4,108 May 15, 2009 08:26 PM
Last Post: gradyeightythree
  OpenGL Color map nkpkd 4 4,139 Mar 30, 2007 10:47 AM
Last Post: nkpkd