Last active
June 20, 2021 09:09
-
-
Save tumen102/2697d413d4f77bdd45f8cb6eb0c82c98 to your computer and use it in GitHub Desktop.
Set openGL colour with a integer instead of floats/doubles.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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