What Is an OpenGL® Circle?

An OpenGL® Circle isn't a shape you can directly draw in OpenGL, as it operates with triangles and vertices. Instead, you craft a circle by plotting points in a loop and connecting them. This creates the illusion of a curve, pivotal in graphics programming. Intrigued by how this shapes your digital world? Let's examine the art behind the code.
Eugene P.
Eugene P.

There is no real built-in shape primitive for a basic Open Graphics Library (OpenGL®) circle, so drawing a circle involves following a simple algorithm to determine the location of the points, after which the points can be connected with lines to form the circle. In most instances, for a real-time rendering application, an OpenGL® circle is approximated and actually is composed of a number of straight lines that look like a circle when the distance between the end points of the lines is short enough. One trick that can help to make a circle smooth is to enable blending and to use the smooth-line drawing mode to reduce the appearance of the angles where two lines connect on the perimeter of the circle. Another way to draw a circle is to use the OpenGL® utility shape primitive known as a disk, which essentially is a two-dimensional (2D) circle that has an additional inner circle that can be set to match the outer edge diameter to somewhat inefficiently draw an OpenGL® circle.

The simple definition of a circle is a 2D shape in which each edge point is the exact same distance from a given center point. The most basic algorithm for drawing an OpenGL® circle is to plot points from a center coordinate using the sine and cosine functions in a loop that steps through the degrees of an angle up to 360°. Stepping 1 degree at a time is fairly inefficient, however, so the steps usually are performed in larger increments. The larger the increments, the more angular the circle will look, with the ultimate example being a circle drawn with only four points, which would make a square.

OpenGL is a software library used for 2D and 3D computer graphics.
OpenGL is a software library used for 2D and 3D computer graphics.

During each step in determining the coordinate of a point on the edge of an OpenGL® circle, a line can be drawn from the last point to the current point. It generally is faster to use a line strip to make a complete circle than to individually draw separate lines. Once the points that comprise the circle have been calculated, they can be stored in an array and translated just like any set of OpenGL® vertices.

An OpenGL® disk is a shape primitive that the OpenGL® utility library can draw natively. It is made of an outer circle and an inner circle, with the area between the inner and outer circles being solid and filled. The OpenGL® disk can be used to draw an OpenGL® circle by setting the inner radius to match the outer radius, although this technique means the circle really is drawn twice because of the inner and outer edges and could leave some graphical artifacts when rotated at different angles.

You might also Like

Discuss this Article

Post your comments
Forgot password?
    • OpenGL is a software library used for 2D and 3D computer graphics.
      By: maya2008
      OpenGL is a software library used for 2D and 3D computer graphics.