(LWJGL) Can I use whole numbers in glClearcolor?

Can I pass integers into glclearcolor? If not, how can i convert a color value such as 135 into a float for it.

OpenGL uses floats for it’s colors, because their easier to do math on. So 1.0 would be full, 0.0 would be empty, and .5 would be half full (or half empty :persecutioncomplex: )

RGB 256 in floats: [icode]color/255[/icode] Example: [icode]135/255 = 0.5294117647[/icode]
RGB floats in 255: [icode]color*255[/icode] Example: [icode]0.5 * 255 = 127.5[/icode]

Dividing the integer by 255f will make it into a float.

This function works on floats in the range [0.0F, 1.0F] only. This of course represents a percentage.

Like with anything else, you can get a percentage by dividing N by it’s limit. The maximum of an RGB integer component is 255.

So you can perform 135/255 to arrive at 0.5294117647058824. Truncate that as needed. :slight_smile:

Edit: Don’t forget about integer division! 135/255 equals 0. One of the numbers must be a float when you divide.