Hello Guest

Color Picking and glColor4ub

  • 3 Replies
  • 8286 Views
Color Picking and glColor4ub
« on: July 12, 2010, 12:01:12 »
Hello everyone,
I must do a picking of many objects. In c++, I use the color picking and glColor4ub to apply "false" color to the object but how to do use this method in java (unsigned char doesn't exist....)?

Thanks
« Last Edit: July 20, 2010, 09:12:04 by darkman19320 »

*

Offline princec

  • *****
  • 1933
    • Puppygames
Re: Color Picking and glColor4ub
« Reply #1 on: July 12, 2010, 12:25:16 »
"Unsigned char" in C more or less maps to (byte) casts on ints in Java. Eg. (byte) 255

Cas :)

Re: Color Picking and glColor4ub
« Reply #2 on: July 12, 2010, 14:06:02 »
Ok thanks. I had some problem with the negative value but it's ok now.

Thanks again

Re: Color Picking and glColor4ub
« Reply #3 on: July 20, 2010, 09:24:28 »
Good morning!
I have resolved the previous problem with the cast.
Unfortunately, I have a new problem: I put the false color to my object using glColor4ub with (for example) the values (-128,-128,-128,-128) and I get my pixel with glReadPixel(x, viewport.get(3) - y, 1, 1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixel) where x and y are the mouse coordinates, viewport.get(3) the window height and pixel a ByteBuffer. The pixel values are -128, -128, -128, -1... why the alpha channel is not equals to -128?

Another problem when I click in different angle on the same object I have, sometimes, the background picked or another object and not the object I clicked on.
If anyone have some hints...
Thanks