Skip to content

Instantly share code, notes, and snippets.

@tumen102
Created June 20, 2021 09:02
Show Gist options
  • Save tumen102/c612d5068dac6abdaa4f3dd83fa4787b to your computer and use it in GitHub Desktop.
Save tumen102/c612d5068dac6abdaa4f3dd83fa4787b to your computer and use it in GitHub Desktop.
Set openGL color with 0xff112233 type value.
public static float[] hexToFloat(int colourToConvert) {
float red = (float) (colourToConvert >> 16 & 255) / 255.0F;
float green = (float) (colourToConvert >> 8 & 255) / 255.0F;
float blue = (float) (colourToConvert & 255) / 255.0F;
return new float[] {red, green, blue};
}
public static void glColorInt(int hexColour) {
float[] rgbValues = hexToFloat(hexColour);
GL11.glColor3f(rgbValues[0], rgbValues[1], rgbValues[2]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment