iDevGames Forums
OpenGL Color Buffer Overwrite - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: OpenGL Color Buffer Overwrite (/thread-1994.html)



OpenGL Color Buffer Overwrite - Talyn - Dec 26, 2008 01:17 AM

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_Selection_Using_Unique_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!


OpenGL Color Buffer Overwrite - ozirus - Dec 26, 2008 12:03 PM

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


OpenGL Color Buffer Overwrite - arekkusu - Dec 26, 2008 12:28 PM

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.


OpenGL Color Buffer Overwrite - Talyn - Dec 26, 2008 12:41 PM

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!


OpenGL Color Buffer Overwrite - Talyn - Dec 26, 2008 12:42 PM

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!!


OpenGL Color Buffer Overwrite - arekkusu - Dec 26, 2008 12:59 PM

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.


OpenGL Color Buffer Overwrite - Talyn - Dec 26, 2008 02:49 PM

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!


OpenGL Color Buffer Overwrite - donny - Dec 30, 2008 03:07 PM

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


OpenGL Color Buffer Overwrite - papillon68 - Jan 4, 2009 02:44 AM

Selection buffer on the Iphone ? Not possible right ?