Friday, December 5, 2008

OpenGL solid cone without glut

The following function draws a solid sphere in OpenGL without glut.

  1: void solidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks)
  2: {
  3:   glBegin(GL_LINE_LOOP);
  4:   GLUquadricObj* quadric = gluNewQuadric();
  5:   gluQuadricDrawStyle(quadric, GLU_FILL);
  7:   gluCylinder(quadric, base, 0, height, slices, stacks);
  9:   gluDeleteQuadric(quadric);
 10:   glEnd();
 11: }
It creates a line loop at line 3. It crates a quadratic object after that (line 4) and sets drawing mode to fill the gaps (line 4, 5).  It calls the gluCylinder() function (line 7). The base radius will be the cone radius. The top radius will be 0 to achieve a cone shape. Finally it deletes the quadratic object (line 9). The result is same as calling glutSolidCone() with the same arguments.