Using Intel® Visual Fortran to Create and Build Windows*-Based Applications

ID 757211
Date 7/23/2021
Document Table of Contents
Give Feedback

Color Mixing

If you have a VGA machine, you are restricted to displaying at most 256 colors at a time. These 256 colors are held in a palette. You can choose the palette colors from a range of 262,144 colors (256K), but only 256 at a time. Some display adapters (most SVGAs) are capable of displaying all of the 256K colors and some (true color display adapters) are capable of displaying 256 * 256 * 256 = 16.7 million colors.

If you use a palette, you are restricted to the colors available in the palette. In order to access all colors available on your system, you need to specify an explicit Red-Green-Blue (RGB) value, not a palette index.

When you select a color index, you specify one of the colors in the system's predefined palette. SETCOLOR, SETBKCOLOR, and SETTEXTCOLOR set the current color, background color, and text color to a palette index.

SETCOLORRGB, SETBKCOLORRGB, and SETTEXTCOLORRGB set the colors to a color value chosen from the entire available range. When you select a color value, you specify a level of intensity with a range of 0 - 255 for each of the red, green, and blue color values. The long integer that defines a color value consists of 3 bytes (24 bits) as follows:

  MSB                    LSB

where R, G, and B represent the bit values for red, green, and blue intensities. To mix a light red (pink), turn red all the way up and mix in some green and blue:

  10000000 10000000 11111111

In hexadecimal notation, this number equals #8080FF. To set the current color to this value, you can use the function:

  i = SETCOLORRGB (#8080FF)

You can also pass decimal values to this function. Keep in mind that 1 (binary 00000001, hex 01) represents a low color intensity and that 255 (binary 11111111, hex FF) equals full color intensity. To create pure yellow (100-percent red plus 100-percent green) use this line:


For white, turn all of the colors on:


For black, set all of the colors to 0:

  i = SETCOLORRGB( #000000)

RGB values for example colors are in the following table.

RGB Color Values


RGB Value


RGB Value



Bright White


Dull Red


Bright Red


Dull Green


Bright Green


Dull Yellow


Bright Yellow


Dull Blue


Bright Blue


Dull Magenta


Bright Magenta


Dull Turquoise


Bright Turquoise


Dark Gray


Light Gray


If you have a 64K-color machine and you set an RGB color value that is not equal to one of the 64K preset RGB color values, the system approximates the requested RGB color to the closest available RGB value. The same thing happens on a VGA machine when you set an RGB color that is not in the palette. (You can remap your VGA color palette to different RGB values; see VGA Color Palette.)

However, although your graphics are drawn with an approximated color, if you retrieve the color with GETCOLORRGB, GETBKCOLORRGB, or GETTEXTCOLORRGB, the color you specified is returned, not the actual color used. This is because the SETCOLORRGB functions do not execute any graphics, they simply set the color and the approximation is made when the drawing is made (by ELLIPSE or ARC , for example).

GETPIXELRGB and GETPIXELSRGB do return the approximated color actually used, because SETPIXELRGB and SETPIXELSRGB actually set a pixel to a color on the screen and the approximation, if any, is made at the time they are called.