Internet
Fact-checked

At WiseGEEK, we're committed to delivering accurate, trustworthy information. Our expert-authored content is rigorously fact-checked and sourced from credible authorities. Discover how we uphold the highest standards in providing you with reliable knowledge.

Learn more...

What Are the Best Tips for OpenGL® Colors?

Eugene P.
Eugene P.

On the surface, and in many basic applications, OpenGL® colors appear to be very simple to use. There are situations and subtleties in the renderer that can sometimes be overlooked, however, causing unexpected results in a scene. These can be caused by the depth of colors or hardware settings. Other times, simple things such as the shading mode can be overlooked and the results of a rendering will be unexpected. Finally, the more complex mechanisms that operate on OpenGL® colors, such as lighting and materials, can drastically affect how the final output looks.

One thing to be sure of in a program using OpenGL® is that all of the correct variables are set. This means ensuring that the shading mode is set to flat or smooth as needed before rendering. The order of the colors also should be set to the expected value. Although nearly all programs use a red, green and blue (RGB) order, there are image formats and other factors where it could be easier to reverse the order and use a blue, green and red (BGR) model.

Woman doing a handstand with a computer
Woman doing a handstand with a computer

One sometimes overlooked, and occasionally difficult, element of OpenGL® colors is color depth. Although a program in development might be created to use the color depth of the development systems monitor, the depth of another user’s monitor might not be the same. This means that, if a program is developed with a 24-bit color depth and run on a system with a 16-bit color depth or an indexed color model, then the scene will not properly render and it might appear that the program does not work. Establishing and adjusting for the available color depth can avoid this type of frustration.

Two areas of OpenGL® colors that have a wide range of nuances capable of producing unwanted results are the lighting and materials systems. When using lighting, it is important to account for the way the light will interact with an object and the potential color of a light, if defined. With improper placement and settings, a light source can wash out colors or alter their appearance. Experimentation might be the only way to find the correct balance between preserving the atmosphere of a scene and accurately rendering the colors.

The materials system can completely change OpenGL® colors on the surface of an object. Setting the ambient, diffuse or specular values too high can result in objects that render completely white, while other settings can make objects black or invisible. The settings on the light source for a scene also can complicate the materials system. When using materials, many problems can be avoided by knowing in detail what each attribute does.

Finally, it can be important to understand the alpha channel used in OpenGL® colors. This is a fourth value in addition to the RGB values of a color that determines the transparency of an object. Many programmers get frustrated attempting to set the alpha value to make a translucent object, only to discover much later that the diffuse attribute color is exclusively used to determine the alpha value of an entire object. The drawing order of the objects, regardless of later transformations, also determines how the alpha value works. This means objects that are transparent and then transformed to a position in front of an object drawn later will not show the object behind it because of the rendering order.

Discuss this Article

Post your comments
Login:
Forgot password?
Register:
    • Woman doing a handstand with a computer
      Woman doing a handstand with a computer