Showing posts with label OpenGL. Show all posts
Showing posts with label OpenGL. Show all posts

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);
  6: 
  7:   gluCylinder(quadric, base, 0, height, slices, stacks);
  8: 
  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.

OpenGL solid sphere without glut

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

  1: void solidSphere(GLdouble radius, GLint slices, GLint stacks)
  2: {
  3:   glBegin(GL_LINE_LOOP);
  4:   GLUquadricObj* quadric = gluNewQuadric();
  5: 
  6:   gluQuadricDrawStyle(quadric, GLU_FILL);
  7:   gluSphere(quadric, radius, slices, stacks);
  8: 
  9:   gluDeleteQuadric(quadric);
 10:   glEnd();
 11: 
 12: }
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).  It draws a sphere using the previously created quadratic object passing the parameters to the function (line 7). Finally it deletes the quadratic object (line 9). The result is same as calling glutSolidSphere() with the same arguments.