SimpleDrawModern gives sample C++ code illustrating the use of Modern OpenGL. It is part of a set of programs introducing the use of Modern OpenGL, which are intended to accompany a possible second edition of the book 3D Computer Graphics: A mathematical approach with OpenGL, Cambridge University Press, 2003.

SimpleDrawModern shows how to draw points, lines, line strips, line loops and triangles. It consists of three source files, SimpleDrawModern.cpp, ShaderMgrSDM.cpp, and ShaderMgrSDM.h. There are several options available for downloading this program:

Things to try out:

  1. Compile and run the program. Use the space bar to toggle between different images.
  2. Check out the features of the SimpleDrawModern program:
    • Rendering using GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP and GL_TRIANGLES.
    • Setting up Vertex Array Objects (VAOs) and Vertex Buffer Objects (VBOs) to hold vertex attributes. Using glBufferData to upload vertex attributes to a VBO.
    • Accepting keyboard input. (Space, Escape, 'X' and 'x'.)
    • Compiling a vertex shader and fragment shader.
    • Using smooth shading (Gouraud shading) for coloring the triangles. glVertexAttribPointer is used to give each vertex its own color.
    • Using generic vertex attributes, specified by glVertexAttrib3f, to use the same color for every vertex. This is done for lines.
    • Using the depth buffer for occlusion.
    • Checking for OpenGL errors on a regular basis.
  3. Try changing the colors of the line segments to different colors, such as cyan and brown.
  4. In the routine my_setup_OpenGL(), experiment with disabling the code that smooths lines. What effect does this have to the rendering of points, lines and polygons? Also try varying parameters to the functions that control point size and line width.
  5. See the more detailed description of the software and its functionality.

Version 1.7 of SimpleDrawModern, September 3, 2020.