Skip to content

Instantly share code, notes, and snippets.

@Bunkerbewohner
Created August 8, 2011 15:24
Show Gist options
  • Save Bunkerbewohner/1131947 to your computer and use it in GitHub Desktop.
Save Bunkerbewohner/1131947 to your computer and use it in GitHub Desktop.
Converting Colour from four floats / bytes to one single (float)
/// <summary>
/// Transforms the 4 color bytes to a single float.
/// The resulting float might not be a valid float number; but only the bytes
/// are important for usage later on the graphics card
/// </summary>
/// <param name="color">Any color</param>
/// <returns>The four color bytes as one float</returns>
Single ConvertColorToSingle(Color color)
{
byte[] bytes = BitConverter.GetBytes(((Color)color).PackedValue);
return BitConverter.ToSingle(bytes, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment