opengl_test


opengl_test a C++ code which uses OpenGL to display graphics information.

OpenGL is most commonly used with C or C++ codes, 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.

OpenGL on Macintosh OS X

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 information on this web page is distributed under the MIT license.

Languages:

opengl_test is available in a C version and a C++ version.

Related Data and Programs:

caustic_opengl, a C++ code which computes a caustic curve and displays it using OpenGL.

fem2d_mesh_display_opengl, a C++ code which reads the finite element method (FEM) model of a 2D mesh, consisting of polygonal elements of any uniform order, and displays an image of the elements and nodes using OpenGL.

fern_opengl, a C++ code which uses OpenGL to display the Barnsley fractal fern.

grf_display_opengl, a C++ code which reads a GRF file defining a mathematical graph and displays it in an OpenGL graphics window.

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

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

lissajous, a C++ code which computes a Lissajous figure and displays it using OpenGL.

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

rotating_cube_display_opengl, a C++ code which displays a rotating color cube in 3D, using OpenGL;

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

sphere_voronoi_display_opengl, a C++ code which displays randomly selected generator points and colors in points on the sphere that are closest to each generator, on the surface of the unit sphere in 3D.

sphere_xyz_display_opengl, a C++ code which reads XYZ information defining points in 3D, and displays a unit sphere and the points, using OpenGL.

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

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

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

xy_display_opengl, a C++ code which reads XY information defining points in 2D, and displays an image using OpenGL.

xyf_display_opengl, a C++ code which reads XYF information defining points and faces in 2D, and displays an image using OpenGL.

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

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

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

xyzl_display_opengl, a C++ code which reads XYZL information defining points and lines in 3D, and displays an image 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. https://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).


Last revised on 24 March 2020.