Chap1TransformFeedback is 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. The code was used to help generate images such as these two spheres:

Chap1TransformFeedback illustrates the use of a Transform Feedback Buffer to allow data that calculated by a a shader program be accessed by the calling C++ program. Chap1TransformFeedback uses a geometry shader to calculate the Transform Feedback Buffer data, but it is also possible to use a vertex shader or a tessellation shader instead. The part of the code that handles the Transform Feedback consists of two core source files, Chap1TransformFeedback.cpp and Chap1TransformFeedback.h, and two files of GLSL shader programs, XformFeedbackChap1.glsl and XformShader.glsl. There are also two specialized files PstricksOutdata.cpp and PstricksOutdata.cpp that use the contents of the Transform Feedback Buffer to generate LaTeX pstricks commands for a couple of figures in Chapter 1 of the text, It also uses GlShaderMgr.cpp and GlShaderMgr.h; these are part of the GlShaderMgr software package. In addition it uses programs from the GlGeomShapes package to render spheres, tori and cylinders. Finally, it uses the GlLinearMath files LinearR3.[cpp,h], LinearR4.[cpp,h], and MathMisc.h.

For information on how to program Transform Feedback in a C++ program with GLSL shaders, see the description of how Transform Feedback is implemented in Chap1TransformFeedback.

To download the Chap1TransformFeedback files:

What is in the Chap1TransformFeedback program:

  1. This is based on the program GlGeomShapesTester. It shows a sphere, a couple cylinders, and a torus. The mesh resolutions are controlled by command 'M', 'm', 'K', 'k', 'L' and 'l'.
  2. Commands '0' and '1' step through selections of different slices or stacks of the sphere and through different slices or stacks of the torus.
  3. If you type 'x1' in the graphics window, the program outputs edge data for the currently selected slice of the sphere to a file. This and and next two commands use Transform Feedback.
  4. If you type 'x2' in the graphics window, the program outputs edge data for the north pole triangle fan of the sphere to a file.
  5. If you type 'x3' in the graphics window, the program outputs edge data for the currently selected slice of the torus to a file.
  6. The purpose of the program is to illustrate the simplest usage of a Transform Feedback Buffer to let the C++ program receive data from the shader program.
  7. Is uses a GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN query to learn the number of records contained in the Transform Feedback Buffer.
  8. It also illustrates how to use glEnable(GL_RASTERIZER_DISCARD) and glDisable(GL_RASTERIZER_DISCARD) to have a shader program that does not use a fragment shader.
  9. For detailed programming explanation, see the description of how Transform Feedback is implemented in Chap1TransformFeedback.

Version 1.0 of Chap1TransformFeedback, May 29, 2019. Updated: May 22, 2020.