What’s an OpenGL® sphere?

Print anything with Printful



An OpenGL sphere is a 3D object made up of triangles or quadrilaterals with equidistant vertices. The number of vertices determines smoothness, with 12 points creating an icosahedron. Subdividing the icosahedron creates a smoother sphere, but texturing can be complex. Using a utility library may be difficult to modify, so custom code may be preferable.

An Open Graphics Library® (OpenGL®) sphere, at its most basic level, is a three-dimensional (3D) object made up of a series of triangles or quadrilaterals whose vertices are all equidistant from a central point. This means that when an OpenGL® sphere is viewed from any angle, the outline appears to the viewer as a perfect circle, although lighting and shading can give the volume a more ball-like appearance. The number of vertices used to create an OpenGL® sphere determines the smoothness of the object in its approximation of a real sphere, with fewer than 12 points creating an object that cannot be considered a sphere. Even though a sphere is considered a primitive form in many graphics applications and libraries, OpenGL® has no innate functionality for rendering a sphere, which means that you need to use supplemental toolkits such as the OpenGL® Utility Toolkit (GLUT) to avoid writing code to manually generate the shape.

When dealing with vertices in OpenGL®, the minimum amount of points that can be used to generate a sphere with some degree of smoothness is 12, creating an object with 20 triangular faces known as an icosahedron. Without further processing, an OpenGL® sphere constructed in this way will have sharp edges visible around the edges, which may be acceptable for some applications. To get a more rounded sphere, each face needs to be further subdivided.

Subdividing an icosahedron to increase the number of vertices it contains and form a smoother OpenGL® sphere results in the creation of new vertices at the center of each edge of each existing triangle. This means that each triangular face will now contain four triangles. The subdivision can continue as long as required, although adding points exponentially can quickly create an object that has a high render time and can become cumbersome to translate.

Despite some of the mathematical conveniences that an OpenGL® sphere offers programmers, such as surface normals that can be easily computed from vertex coordinates, texturing a sphere can present some complexities. Using a standard two-dimensional (2D) texture projected onto the sphere means that the top and bottom areas of the texture image will be compressed, as the shape of the triangles near the sphere’s poles are compressed. To work around this, cube mapping could be used, or the programmer could manually generate texture coordinates for the object.

One factor should be noted about using a utility library to generate an OpenGL® sphere. A sphere generated from GLUT or similar toolkits can sometimes be difficult to modify, optimize and manage within OpenGL® itself. For this reason, it is sometimes useful to use custom written code to generate an OpenGL® sphere so that it is created and can be used as efficiently as possible within your program.




Protect your devices with Threat Protection by NordVPN


Skip to content