Skip to content

Instantly share code, notes, and snippets.

@tumen102
Last active June 20, 2021 09:09
Show Gist options
  • Save tumen102/2697d413d4f77bdd45f8cb6eb0c82c98 to your computer and use it in GitHub Desktop.
Save tumen102/2697d413d4f77bdd45f8cb6eb0c82c98 to your computer and use it in GitHub Desktop.
Set openGL colour with a integer instead of floats/doubles.
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]);
}
// example ColourUtil.glColorInt(0xff8080ff);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment