how to get a pixels exact color? (no floats)

hello, i am trying to get a pixels color in 8Bit RGB mode, so i try this:

ByteBuffer snap = ByteBuffer.allocate(3);

gl.glReadPixels(mp.mouseX, mp.mouseY, 1, 1, GL.GL_RGB, GL.GL_BYTE, snap );

unfortunately this gives me values from 0 to 127 only, which would be 7Bit per channel.

Replacing GL_BYTE with GL_UNSIGNED_BYTE should do the trick.

thanks,
i tried that, but that gives me strange results.

for white pixels it gives me -1,-1,-1 and for black pixels 0,0,0
for other colors it gives me values from -127 to 50 (probably 127, but i havent seen values higher than 50)

and most interestingly of all, they dont seem to be in RGB order anymore, but sometimes in GBR and sometimes in BGR.

maybe there is a problem with my buffer?

i do snap.rewind() every frame.

OpenGL is giving you an 8bit unsigned value, but Java is interpreting it as an 8bit signed value. So for instance, OpenGL returns 255, but Java sees -1. Since java does not have an unsigned byte type, you need to promote the byte values to a wider data type to get the correct values.

byte incorrectValue = -1;
int correctValue = incorrectValue & 0xFF;

yes thats much better!

thank you very much!