Display a Caustic using OpenGL

CAUSTIC_OPENGL is a C++ program which computes a caustic curve based on user input, and uses OpenGL to display it.

The user specifies a value Q, the number of points, a value P which controls which points will be connected, and values A and B which determine the curve on which the points lie.

The program then plots Q points along the curve

x(I) = cos ( A * 2 * i * pi / Q )
y(I) = sin ( B * 2 * i * pi / Q )
and connects each point I to point I+P, using modular arithmetic where necessary.


caustic_opengl q p a b

OpenGL on Macintosh OS X

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

Note that this source code and compilation script have been adapted for use on a Macintosh running OSX.

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

        # include <GL/glut.h>

        # include <GLUT/glut.h>

The compilation statement, which might ordinarily be

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

        g++ caustic_opengl.C -m -framework OpenGL -framework GLUT


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


CAUSTIC_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.

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.

OPENGL, C++ programs which illustrate the use of the OpenGL graphics library;

OBJ2OPENGL, a PERL 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.

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

ROTATING_CUBE_DISPLAY_OPENGL, a C++ program which displays a rotating color cube in 3D, 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.

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.


  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.
    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 20 October 2009.