Why do some OpenGL parameters accept 0.0-1.0?

Why do some OpenGL parameters take a value between 0.0 and 1.0 for some functions like glColor3f and glNormal3? This is a question that has always bothered me; I have always been from the beginning of my 3D programming career, but initially I just agreed with it, like any other sheep following the flock. But why 0.0-1.0? Was it an arbitrary choice made by the Khronos group, or something more existential?

+3


source to share


1 answer


Since values ​​less than 0 or more than 1 don't make sense for these things.

For colors, a typical representation for display purposes is an 8-bit integer from 0 to 255, but OpenGL is not limited to this particular representation; GL implementation can also support things like 48-bit color (16 bits per channel) or floating point color components. To be independent of the underlying representation, color components in OpenGL are represented as fractions from 0% to 100%, which are expressed as numbers 0.0 and 1.0. The GL implementation converts these values ​​to the format that the display actually uses (for example, the typical 0-255).

The normals must be vectors of unit length, which means that the length of each component naturally cannot be greater than 1; otherwise, the length of the entire vector will be greater than 1.



Note that these values ​​should not actually be in the 0.0-1.0 range:

  • For colors, your monitor cannot display more than 100% luminance, but a color component greater than 1.0 can be helpful if multiplied by something (like a texture or scaling factor) that will bring it back into range. This is commonly used for HDR .
  • Normal vectors without a unit are not very useful for legacy fixed function lighting that sounds like you are using it as they are not real world physics, but you can specify anyway and you will get results that are mathematically correct (although and not realistic or useful). You can also specify normals without a unit and have OpenGL automatically scale them to block length using GL_NORMALIZE

    .

    Unitless vectors can be useful in programs that use custom shaders to perform complex lighting calculations.

+3


source







All Articles