Display Unit Sphere and 3D Points Using OpenGL

SPHERE_XYZ_DISPLAY_OPENGL is a C++ program which reads the name of a data file containing a list of 3D point coordinates, reads the data, and displays a unit sphere and the points using OPENGL.

It can be difficult to visualize a set of points that lie on the unit sphere. You can't see the curving surface, and you can see points that should not be visible, because they are on the other side of the sphere. By starting the display with a unit sphere, and then adding the 3D points you want to see, both of these problems are resolved. The addition of the sphere gives important visual cues as to how to "read" the data.

The program displays the data, and slowly rotates it. Clicking the mouse stops the rotation; another click starts it again, with rotation around a different axis.


sphere_xyz_display_opengl data.txt


The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.


SPHERE_XYZ_DISPLAY_OPENGL is available in a C++ version.

Related Data and Programs:

FERN_OPENGL, a C++ program which uses OpenGL to display the Barnsley fractal fern.

SCREENSHOT_OPENGL, a C++ program which shows how a program using the OpenGL graphics library can save a screenshot of the graphics being displayed.

SPHERE_XYZ_DISPLAY, a MATLAB program which reads XYZ information defining points in 3D, and displays a unit sphere and the points in the MATLAB graphics window.

XY_DISPLAY_OPENGL, a C++ program which reads an XY file of 2D point coordinates, and displays an image of those points using OpenGL.

XYZ, a data directory which contains some examples of 3D pointsets.

XYZ_DISPLAY_OPENGL, a C++ program which reads XYZ information defining points in 3D, and displays an image using OpenGL.

XYZF_DISPLAY_OPENGL, a C++ program which reads XYZF information defining points and faces in 3D, and displays an image using OpenGL.

XYZL_DISPLAY_OPENGL, a C++ program which reads XYZL information defining points and lines in 3D, and displays an image using OpenGL.


  1. Edward Angel,
    Interactive Computer Graphics, a Top-Down Approach with OpenGL,
    Addison-Wesley, 2000,
    ISBN: 0-201-38597-X,
    LC: T385.A514.
  2. Renate Kempf, Chris Frazier, editors,
    OpenGL Reference Manual,
    Fourth Edition,
    Addison-Wesley, 2004,
    ISBN: 032117383X,
    LC: T385.O642
  3. Mason Woo, Jackie Neider, Tom Davis,
    OpenGL Programming Guide,
    Addison-Wesley, 1997,
    ISBN: 0-201-46138-2,
    LC: T385.N435
  4. Richard Wright, Michael Sweet,
    OpenGL Superbible,
    Third Edition,
    Sams, 2004,
    ISBN: 0672326019,
    LC: T385.W73
  5. http://www.opengl.org/
    The official OpenGL site.

Source Code:

Examples and Tests:

List of Routines:

You can go up one level to the C++ source codes.

Last revised on 28 August 2010.