Negative values in selectbuffer

I am currently implementing Picking with glPickMatrix()…

Why do i have negative values for the distance of the objects in the glSelectBuffer ?

It seems as if objects that are farther, got lower values, namely these negative values.

What can I do ? ???

This is due to a conversion error from c to java. The select buffer actually contains unsigned integers, but java interprets the values as signed integers. To get the correct value you can do the following

int incorrectUnsignedValue = 1 << 31; // -2147483648
long correctUnsignedValue = incorrectUnsignedValue & 0xFFFFFFFFL; // 2147483648

You also need to make sure that the select buffer is allocated in the native byte order, or you’ll get all kinds of funkiness going on.

IIRC, there are methods in BufferUtils to do this.

ok thank you pepijnve :slight_smile:

You solution solved my problem…

I just encountered this same problem – it would be great if the picking example in the Jogl demos.misc package was updated to reflect this conversion.

Chris

As far as I can tell the demos.misc.Picking example is doing its Z conversion correctly. I just updated the example to fix the package name and to add different Z values for the three rectangles. Let me know if you have a suggestion on how the demo should be changed.

to fix this I just used gl.glDepthRange(0.0d,0.01d);

Presumably this reduces the accuracy of the depth values but it works!