Picking, next steps

I have picking working and if I click an object, chooseNum below is #0, if I click in empty space I got no chooseNum at all, which is what I would expect. Now how do I get form a 0 to an acutal object to act upon? Here is the bottom half of my pick code:


hits = GL11.glRenderMode(GL11.GL_RENDER);                               
String chooseNum = "";
if(hits > 0) {                                               
int choose = buffer[3];                                  
int depth = buffer[1];                                   

for (int i = 1; i < hits; i++) {                
    // If This Object Is Closer To Us Than The One We Have Selected
    if (buffer[i * 4 + 1] < (int)depth) {
	choose = buffer[i * 4 + 3];                      
	depth = buffer[i * 4 + 1];                       
    }
}
	chooseNum = "#" + choose;
	//testMessage = "[HIT] choose: " + choose;

// now print the chooseNum test message to the screen

}

Thanks

M

ok, I have gotten a little further. My pick return an int name like so:

1677726

but the object I clicked the mouse on called a glLoadName(1)

Object 2 was glLoadName(25)
but pick returns the name 47689996

Am I missing a conversion?

http://192.18.37.44/forums/index.php?topic=9147.0

Besides that, a technique called color-coding is a LOT faster on ATi cards.

Just for you to know :slight_smile:

Thanks for the link…didnt come up in my search !

[quote]Besides that, a technique called color-coding is a LOT faster on ATi cards.
[/quote]
What is that?

You could have googled it, but well, here we go:

Rendering all ‘objects’ in a unique color.
Then do a glReadPixels() for 1 pixel where the mouse is.
You receive the color of the pixel, which maps directly to the object.

  • doesn’t work if you’re blending, so disable that while picking, also disable textures and lighting

If you pick this way, you first do the color-coding, read color, clear colorbuffer/depthbuffer, draw as normal.

So you shouldn’t pick every frame as it will cut your framerate in half. The same (or much worse, on ATi) would count for OpenGL Picking.

Thanks!

I tried the code fomr the link as well as the code from the 2nd message of that link and all three give me the same ‘name’ for my objects. 4975845557 where I thought I would get 24. Very odd.

M

big endian to little endian and I now have picked id’s !! ;D

Just out of interest, why?

AFAICS (which usually isn’t far), the operations for picking and colour-coding are pretty much identical. In fact, due to the diminutive extent of the picking frustrum, the vast majority of polygons will not have to be rasterized, which would make picking a bit faster.

So what are ATI doing that’s so weird?