SimpleNurbs
A program that draws a rational Bezier patch.

SimpleNurbs is a C program illustrating the use of OpenGL.   It is intended to accompany the book 3D Computer Graphics: A mathematical approach with OpenGL, by S. Buss, Cambridge University Press, 2003.   However, it can be used independently as well.

SimpleNurbs draws a single rational Bezier patch.  As such, it is somewhat misleadingly named: it might have better been called "SimpleRationalBezier", but that seemed to be too awkawrd a name.   The C code consists of two source files, SimpleNurbs.c and SimpleNurbs.h.   There are several options available for downloading this program:

Things to try out:

  1. Compile and run the program.  There a number of keyboard controls:
    1. Press arrow keys (left, right, up and down) to make the patch rotate.
    2. Press "s" to single step the animation,
    3. Press "a" to start the animation running again without stopping.  (Undoes the "s" effect.)
    4. Press "r" to reset the patch back to its original orientation with no velocity.
    5. Press "0" (zero) to zero the velocity of the patch, but leave its position fixed.
    6. Press "p" to toggle between rendering in filled polygon mode, and in wireframe mode.
    7. Press "f" to toggle between flat shading and smooth shading.
    8. Press "U" to increase the patch resolution in the "u" direction.
    9. Press "u" to decrease the patch resolution in the "u" direction.
    10. Press "V" to increase the patch resolution in the "v" direction.
    11. Press "v" to decrease the patch resolution in the "v" direction.
  2. Experiment with increasing the resolution of the mesh (controls "U" and V").  Note how the specular highlights become better defined as the resolution increases.   Examine the code and see how the patch resolution is increased and decreased.
  3. The crosssections of the Bezier patch are perfectly circular.  This is possible only with rational Bezier patches: review the theory in Chapter 7, and compare to how it is implemented in the program. 
  4. The program uses Bezier patches of order 4x4 or of order 3x4.  As initially setup, it uses order 4x4.  Thus, its circular cross sections are defined with four control points: the middle control points have weight 1/3.
  5. Try changing the variable  USE_CNTLPT_AT_INFINITY to have value 1 instead of 0.   This changes the program so that it uses a Bezier patch of order 3x4 (order 3 in u, order v in v).  Now the circular crosssections are semicircles defined with order three Bezier curves, and thus use control points which are points at infinity.
  6. You should be able to see specular highlights and other Phong lighting effects on both sides of the Bezier patch.  Is this true for you?  I had to set the "Front Face" option to "clockwise", with glFrontFace(GL_CW).    This doesn't seem like it should have been necessary --- is this a standard OpenGL feature or a bug in OpenGL on my PC?  (Any experts out there?  Please let me know.)