These programs show complete sample programs for using Modern OpenGL. These programs are based on older legacy OpenGL programs which were written for the book 3D Computer Graphics: A mathematical approach with OpenGL, by Sam Buss, Cambridge University Press, 2003. It is hoped that in the near future, all of those legacy OpenGL programs will be translated to Modern OpenGL, to support the course Math155A/B at UCSD during Winter and Spring 2017.

These programs are still UNDER DEVELOPMENT. Corrections or improvements (minor and major) will be very much welcomed!

Some programs are supplied with Visual Studio 2015 project and workspace files; however, the source files should work with other compilers and on other systems as well. You will need to have OpenGL, GLFW, and GLEW installed: namely, the header files to compile programs and the object libraries to link and run the programs. See below for more on obtaining GLFW and GLEW.

I. Getting started with basic features.

  1. SimpleDrawModern shows how to draw points, lines, line strips, line loops, and triangles. It includes simple vertex and fragment shaders. It accepts keyboard inputs to update the scene.
  2. SimpleAnimModern shows how to draw triangles, triangle strips, and triangle fans; how to use an orthographic projection matrix, how to use model view matrices, and to do a simple rotational animation.
  3. SolarModern animates a simple solar system with a sun, an earth and a moon. It uses a perspective projection matrix and implements a hierarchical use of modelview matrices. It contains simple animation controls, and uses GlGeomSphere to render spheres. (COMING SOON)
  4. BasicDrawModes illustrates drawing multiple triangle strips in four of the basic drawing modes for OpenGL: glDrawArrays, glDrawElements, glMultiDrawElements, and glDrawElements with Primitive Restart.
  5. ConnectDotsModern illustrates detecting mouse clicks, and drawing straight-line segments joining points.

II. Utilities and helper classes

  1. GlGeomShapes. C++ classes encapsulating some simple geometric shapes. So far, spheres and cylinders are available. (UNDER FURTHER DEVELOPMENT)
  2. GlLinearMath gives C++ classes for vectors, matrices, quaternions, and miscellaneous math functions.
  3. GlShaderMgr C++ classes for reading GLSL shader programs from files, for compiling and linking them, and for working with vertex attributes and uniform data items across multiple shaders. (UNDER FURTHER DEVELOPMENT)
  4. RgbImage gives a C++ class for reading and writing textures to and from bitmap (.bmp) files.

III. Programs with more complex shaders

  1. SimpleDrawGlShaderMgr is a "re-do" of SimpleAnimModern, but now loading the shaders's source code from a file, using the above GlShaderMgr class.
  2. SimpleLightModern illustrates both Phong lighting with Gouraud shading and Phong lighting with Phong shading. Allows several viewing options, including seeing the different light components separately. Uses the GlShaderMgr class to load shaders formed more than one code block.
  3. TextureBmpModern illustrates a simple case of how to use a single texture map.
  4. FourTexturesModern illustrates how to use four texture maps at once. It also illustrates how use glDrawElementsBaseVertex.
If you have a compiler installed on your computer, it very likely comes with the needed OpenGL headers and libraries, but you still need the GLFW and GLEW headers and libraries. GLFW provides a platform-independent (more-or-less) interface to OpenGL so that the same code can be used for different operating systems, including Windows, Macs, and Linux. GLEW is the "OpenGL Extension Wrangler Library": it tracks which features ("extensions") of OpenGL are available in your computer system, and is simplifies the interface to OpenGL.

Obtaining GLFW. GLFW files are available from For Windows machines, the header files and binary files (library files) are available for direct download, by clicking on the "Download" header on that web page. After you obtain the header files (.h) and the Windows library files (.lib), install them on your system (as administrator) in the same location as GL/glu.h and glu32.lib. Installing the .dll files should not be necessary, as it is recommended to use static linkage. If you do not have administrator privileges, you may instead store the files locally.
For non-Windows machines, you will need to compile GLFW from its source code: this is also available at along with CMake files.
If you compile and link with makefiles instead of using Visual Studio projects, you may wish to remove the #pragma commands in the .cpp files.

Obtaining GLEW. GLEW files are available from Installation directions are the same as for GLFW above.

Acknowledgements: I initially started learning Modern OpenGL primarily from the OpenGL Programming Guide, Ninth Edition (Kindle version), and the Learn OpenGL website by Joey de Vries. Books on Modern OpenGL include the OpenGL Programming Guide and the OpenGL Super Bible; if you get one, be sure it is for OpenGL 4.3 or later. The LearnOpenGL website also provides a PDF version of itself available for download as a complete online book. For somewhat denser reading, the official specification of OpenGL 4.5 is available online at