OpenGL
Examples of OpenGL Graphics


OpenGL is a directory of C++ programs which use the Open GL graphics library to display graphics information.

It is possible to do a wide range of sophisticated 2D and 3D graphics presentations. OpenGL v1.1 software runtime is included as part of the operating system for WinXP, Windows 2000, Windows 98, Windows 95 (OSR2) and Windows NT. The OpenGL v1.1 libraries are also available as a self-extracting archive file from the Microsoft Site via HTTP or FTP.

OpenGL is most commonly used with C or C++ programs, but can also be called by a FORTRAN program if the necessary intermediate "FORTRAN bindings" (an interface package) have been installed.

OpenGL only does graphics rendering, and has no concept of windowing systems, input devices, printing to the screen and so on. These extra functions must be provided by an auxilliary package. One common package as known as GLUT, for the Graphics Language Utility Toolbox.

Local Implementation:

OpenGL is available on the SCS Alpha systems chili and kachina. The "include" files should be accessible using a statement like

        # include <GL/gl.h>
        # include <GL/glu.h>
        # include <GL/glut.h>
      
The compiled libraries can be accessed by a command like
        g++ myprog.C -lm -lGL -lGLU -lglut
      

OpenGL is available on the SCS "hallway" systems such as quadrature. The "include" files should be accessible using a statement like

        # include <GL/gl.h>
        # include <GL/glu.h>
        # include <GL/glut.h>
      
The compiled libraries can be accessed by a command like
        g++ myprog.C -lm -lGL -lGLU -lglut
      

OpenGL is available on the SCS Prism systems. The "include" files should be accessible using a statement like

        # include <GL/gl.h>
        # include <GL/glu.h>
        # include <GL/freeglut.h>
      
The compiled libraries can be accessed by a command like
        g++ myprog.C -lm -lGL -lGLU -lglut
      

OpenGL on Macintosh OS X

OpenGL ships with OS9 and OSX for the Macintosh. You can obtain the latest software version on the Apple OpenGL web site.

Note that the source code and compilation script have been adapted for use on a Macintosh running OS X.

For that reason, the include file references have been changed from:


        # include <GL/gl.h>
        # include <GL/glu.h>
        # include <GL/glut.h>
      
to:

        # include <OpenGL/gl.h>
        # include <OpenGL/glu.h>
        # include <GLUT/glut.h>
      

The compilation statement, which might ordinarily be


        g++ myprog.C -lGL -lGLU -lglut
      
was modified to:

        g++ myprog.C -framework OpenGL -framework GLUT
      

Licensing:

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

Languages:

OPENGL examples are available in a C version and a C++ version.

Related Data and Programs:

CAUSTIC_OPENGL, a C++ program which computes a caustic curve and displays it using OpenGL.

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

LIFE_OPENGL, a C++ program which simulates a version of John Conway's "Game of Life", displaying the results using OpenGL.

LIGHTS_OUT_OPENGL, a C++ program which sets up a "Lights Out" game and allows the user to solve it, using the OpenGL graphics window.

LISSAJOUS_OPENGL, a C++ program which computes a Lissajous figure and displays it using OpenGL.

POLYGONAL_SURFACE_DISPLAY_OPENGL, a C++ program which displays a surface in 3D described as a set of polygons, using OpenGL.

PPMA, a data directory which describes the ASCII Portable Pixelmap format, which is a possible means of storing the graphics information displayed by OpenGL. One of the example programs shows how this can be done.

ROTATING_CUBE_DISPLAY_OPENGL, a C++ program which displays a rotating color cube in 3D, using OpenGL;

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_OPENGL, a C++ program which reads XYZ information defining points in 3D, and displays a unit sphere and the points, using OpenGL.

TET_MESH_DISPLAY_OPENGL, a C++ program which reads a pair of files defining a tetrahedral mesh and displays an image using OpenGL.

TRI_SURFACE_DISPLAY_OPENGL, a C++ program which displays the 3D graphics information in a TRI_SURFACE file using OpenGL.

TRIANGULATION_DISPLAY_OPENGL, a C++ program which reads a pair of files defining a triangulation and displays an image using OpenGL.

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

XYL_DISPLAY_OPENGL, a C++ program which reads XYL information defining points and lines in 2D, and displays an image using OpenGL.

XYZ_DISPLAY_OPENGL, a C++ program which reads an XYZ file of 3D point coordinates, and displays an image of those points using OpenGL.

Reference:

  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.

Examples and Tests:

GASKET_POINTS displays the Sierpinksi gasket by showing 5000 points.

GASKET_POINTS_3D displays the 3D Sierpinksi gasket by showing 100000 points.

GASKET_POLY_FILLED displays the Sierpinksi gasket by drawing filled polygons.

GASKET_POLY_OPEN displays the Sierpinksi gasket by showing open polygons (actually, "line loops").

GASKET_TO_PPMA displays the Sierpinksi gasket, copies the pixels to an array, and writes that array to an ASCII PPM file.

SHADED SPHERES allows the user's mouse to move a light source for some spheres.

SHADING allows the user to display the shading method on some objects. However, it is also an interesting example of the use of the include files created by the OBJ2OPENGL script, which converts OBJ files of 3D data into C include files, which can then be used in an OpenGL program to display the object. Here, we will display figures of a gourd and a bird that were created in this way. Files you may copy include:

TURTLE allows the user's mouse clicks to turn a line to the left or right. Files you may copy include:

VORONOI_DISPLAY displays a Voronoi diagram, involving 9 points in the unit square (in blue) and the lines that indicate the boundaries of the Voronoi regions (in red).

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


Last revised on 20 June 2006.