What are OpenGL® lines? (29 characters)

Print anything with Printful



OpenGL can draw lines between two vertices, but they may take longer to render and have unexpected results. Lines can be used for 2D display indicators and can be combined to form line stripes and loops. The width of a line can be defined, but there is no standard. Lines may not display properly due to floating point math.

In the Open Graphics Library® (OpenGL®), lines are one of the basic primitive shapes that OpenGL® is capable of drawing, and they form one of the building blocks that are sometimes used to render triangles. OpenGL® lines are just a straight and connecting graphics between two vertices. While the concept and execution of OpenGL® lines may be simple, they tend to take longer to render than other primitives in some implementations, in part because there are no specifications about their behavior in the OpenGL® standard. Explicit use of OpenGL® lines can sometimes have unexpected results, because the lines are rasterized in a specific way that might make them appear detached from other geometry in the scene or appear slightly off where they should be. In addition to a baseline, OpenGL® lines can also be formed into line stripes and loops, just like triangular stripes, with the end of each line representing the start of the next.

When used in a scene, OpenGL® lines are a type of primitive shape consisting of two vertices, or coordinates in three-dimensional (3D) space, connected by a straight, visible path. Unlike other primitives, such as a triangle, a line generally doesn’t have a surface, although it can still be colored by blending and using vertex coloring. Lines are often used in mathematical and scientific 3D displays, as well as for two-dimensional (2D) display indicators, such as crosshairs or arrows that point to areas of the display, for the viewer.

The width of a line can be defined to some extent via OpenGL®. You can specify how many pixels wide the line should be at any given point, though there’s no real standard for how that should work from platform to platform. In some situations, the width cannot be changed at all while, in other cases, the width of OpenGL® lines is limited to a seemingly arbitrary number.

In addition to the baseline, multiple OpenGL® lines can be combined to form two other structures known as line stripes and line rings. Line streaks are simply a sequence of vertices where the start of each new line is the end point of the last line. This is mostly a convenience feature, but it can render faster than using single lines. A line loop is nearly identical to a line stripe, except that the last vertex of the loop is then reconnected to the first specified vertex.

One complication when using OpenGL® lines is that since they are only 1 pixel wide by default, they sometimes don’t display properly. In some cases, especially if the line is anti-aliased, some pixels in the rasterized image may not display. The line itself might even appear a few pixels away from where it should be. This is largely caused by tiny variations in the floating point math used by OpenGL®; it’s not always a problem that can be easily fixed without converting lines to polygons for rendering purposes.




Protect your devices with Threat Protection by NordVPN


Skip to content