Update: I’m getting close. Now, the output colors are exactly half what they should be… If i put in
glColorf(90/255f, 40/255f, 133/255f)
It outputs R: 45 G: 20 B: 66
Now my code looks like this:
ByteBuffer pRGB = ByteBuffer.allocateDirect(12);
GL11.glReadPixels(x, 600-y, 1, 1, GL11.GL_RGB, GL11.GL_BYTE, pRGB);
pRGB.rewind();
System.out.print("R:");
System.out.print((pRGB.get() & 0xff ));
System.out.print("G:");
System.out.print((pRGB.get() & 0xff));
System.out.print("B:");
System.out.print((pRGB.get() & 0xff));
OLD:
So I’m still working on color picking. Now the problem comes down to a color conversion problem. I set each primitive to a unique color using:
glColor3f(glColor[0]/255f,glColor[1]/255f, glColor[2]/255f) where glColor is an array of ints with each cell between 0 and 255.
Getting the pixel data looks like this:
//Disable anything that could affect color
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_FOG);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable (GL11.GL_BLEND);
GL11.glDisable (GL11.GL_DITHER);
GL11.glDisable (GL11.GL_TEXTURE_1D);
GL11.glShadeModel (GL11.GL_FLAT);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
//Set up buffer to store pixel data
ByteBuffer pRGB = ByteBuffer.allocateDirect(12);
FloatBuffer fRGB = pRGB.asFloatBuffer();
//Render primitives with unique color
RenderColors()
//Read pixel
GL11.glReadPixels( WindowWidth,WindowHeight-y, 1, 1, GL11.GL_RGB, GL11.GL_FLOAT, fRGB);
//Set buffer back to start
pRGB.rewind();
fRGB.rewind();
//Output pixel color
System.out.print("R:");
System.out.print((int)(pRGB.get() & 0xff));
System.out.print("G:");
System.out.print((int)(pRGB.get() & 0xff));
System.out.print("B:");
System.out.print((int)(pRGB.get() & 0xff));
Help?