Stroke drawing in OpenGL

Here is the C++ source code that I used in some of my painterly rendering papers to draw brush strokes in OpenGL:

The code consists of a C++ object, Stroke. You define a control polygon for the stroke, along with other attributes (such as radius and color). The control polygon defines an endpoint-interpolating cubic B-spline. During your OpenGL display loop, you can then render the stroke by calling its render() method, which renders the stroke as a triangle strip, plus optional rounded ends. Details of how the tesselation is computed are in Section 5.1 of my SIGGRAPH 2002 course notes.

I am releasing this software on the web in hopes that it will be useful to other researchers. I've compiled this code (or variants) on several platforms, including Linux with gcc, and Windows with Visual Studio. Sorry for the rough edges and lack of documentation.

A simple usage example:

   Stroke str;
   str.radius = 8;  // set the stroke to be 8 pixels wide;
   str.add(10,10);  // add some control points
   str.curveType = CUBIC_BSPLINE;
   str.z = 0;    // Z coordinate for Z-buffering
   str.useTexture = false;  // disable texturing

   // in the OpenGL display loop

If useTexture is set to true, then the stroke renderer also generates texture coordinates. This can be used to map a texture or opacity map onto the stroke.

Pixel-wise scan-conversion

Instead of using OpenGL polygon operations, this code can also scan-convert strokes pixel-by-pixel. To do so, #define SCAN_CONVERT within Stroke.cpp, and add these two files:

A sample program

Aaron Hertzmann