public static void gear(GL2 gl,
      float inner_radius,
      float outer_radius,
      float width,
      int teeth,
      float tooth_depth) {
      int i;
      float r0, r1, r2;
      float angle, da;
      float u, v, len;

      r0 = inner_radius;
      r1 = outer_radius - tooth_depth / 2.0f;
      r2 = outer_radius + tooth_depth / 2.0f;

      da = 2.0f * (float) Math.PI / teeth / 4.0f;

      gl.glShadeModel(GL2.GL_FLAT);

      gl.glNormal3f(0.0f, 0.0f, 1.0f);

      /* draw front face */
      gl.glBegin(GL2.GL_QUAD_STRIP);
      for (i = 0; i <= teeth; i++) {
         angle = i * 2.0f * (float) Math.PI / teeth;
         gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
         gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
         if (i < teeth) {
            gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
            gl.glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da), width * 0.5f);
         }
      }
      gl.glEnd();

      /* draw front sides of teeth */
      gl.glBegin(GL2.GL_QUADS);
      for (i = 0; i < teeth; i++) {
         angle = i * 2.0f * (float) Math.PI / teeth;
         gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
         gl.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
         gl.glVertex3f(r2 * (float) Math.cos(angle + 2.0f * da), r2 * (float) Math.sin(angle + 2.0f * da), width * 0.5f);
         gl.glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da), width * 0.5f);
      }
      gl.glEnd();

      /* draw back face */
      gl.glBegin(GL2.GL_QUAD_STRIP);
      for (i = 0; i <= teeth; i++) {
         angle = i * 2.0f * (float) Math.PI / teeth;
         gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
         gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
         gl.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
         gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
      }
      gl.glEnd();

      /* draw back sides of teeth */
      gl.glBegin(GL2.GL_QUADS);
      for (i = 0; i < teeth; i++) {
         angle = i * 2.0f * (float) Math.PI / teeth;
         gl.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
         gl.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f);
         gl.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
         gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
      }
      gl.glEnd();

      /* draw outward faces of teeth */
      gl.glBegin(GL2.GL_QUAD_STRIP);
      for (i = 0; i < teeth; i++) {
         angle = i * 2.0f * (float) Math.PI / teeth;
         gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
         gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
         u = r2 * (float) Math.cos(angle + da) - r1 * (float) Math.cos(angle);
         v = r2 * (float) Math.sin(angle + da) - r1 * (float) Math.sin(angle);
         len = (float) Math.sqrt(u * u + v * v);
         u /= len;
         v /= len;
         gl.glNormal3f(v, -u, 0.0f);
         gl.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
         gl.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
         gl.glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
         gl.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), width * 0.5f);
         gl.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f);
         u = r1 * (float) Math.cos(angle + 3 * da) - r2 * (float) Math.cos(angle + 2 * da);
         v = r1 * (float) Math.sin(angle + 3 * da) - r2 * (float) Math.sin(angle + 2 * da);
         gl.glNormal3f(v, -u, 0.0f);
         gl.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), width * 0.5f);
         gl.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
         gl.glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
      }
      gl.glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), width * 0.5f);
      gl.glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), -width * 0.5f);
      gl.glEnd();

      gl.glShadeModel(GL2.GL_SMOOTH);

      /* draw inside radius cylinder */
      gl.glBegin(GL2.GL_QUAD_STRIP);
      for (i = 0; i <= teeth; i++) {
         angle = i * 2.0f * (float) Math.PI / teeth;
         gl.glNormal3f(-(float) Math.cos(angle), -(float) Math.sin(angle), 0.0f);
         gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
         gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
      }
      gl.glEnd();
   }