We set the pattern used in line stippling with the OpenGL function glLineStipple, which requires two parameters. The second parameter is an unsigned short (i.e., a 16-bit number) and defines the stippling pattern while the first sets the stretch factor. The 0s and 1s in the binary representation of pattern determine how the pixels forming the line are displayed. The binary representation of the hexadecimal number 0x1E3F used for generating the third line is
0001 1110 0011 1111
Starting with the low-order bits and moving left in the number, a 1 means the pixel is on (gets the line color) and a 0 means the pixel is off (does not get the line color). The factor multiplies the number of 1s and 0s in the subparts of pattern and, in essence, stretches the pattern. The pattern (or stretched pattern) is repeated as many times as necessary to cover the line being rendered. If the geometry type is line strip or line loop, the pattern continues over the common vertices without restarting at each endpoint. We use in our example three patterns 0x30FC, 0x03FF and 0x1E3F with a multiplier of 3 in each case. As usual for any OpenGL state variable, when the current pattern is set, it is applied until a new pattern is set or line stippling is disabled.