When we use floating-point attributes, we need to specify each color component in a
range from 0 to 1, with 1 being the maximum value for that color component. Figuring
out the right numbers for a certain color might not be obvious, but by using Android’s
Colorclass, we can easily come up with the right values. For example, here’s what we
do to get the OpenGL color values for green:
floatred=Color.red(Color.GREEN)/255f;
floatgreen=Color.green(Color.GREEN)/255f;
floatblue=Color.blue(Color.GREEN)/255f;
We can also do this with web colors:
intparsedColor=Color.parseColor("#0099CC");
floatred=Color.red(parsedColor)/255f;
floatgreen=Color.green(parsedColor)/255f;
floatblue=Color.blue(parsedColor)/255f;
The values returned by Color.red(), Color.green(), and Color.blue()range from 0 to 255, so
to convert these into OpenGL colors, we just divide each component by 255.
评论