Creating Simple 3D Objects Using GLUT

There are several GLUT utility functions for creating both wire frame and solid objects. To create a sphere, use either of the following:

void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);

void glutWireSphere(GLdouble radius, GLint slices, GLint stacks);

Here, radius is the radius of the sphere. The slices argument is the number of flat bands created around the z-axis. The higher the number of slices, the rounder the sphere. The stacks argument is the number of flat bands along the z-axis. The higher the slices value, the rounder the sphere. Lower slices and stacks values produce shapes that are drawn quicker. A sphere is drawn (or rendered) centered at the origin in modeling coordinates (for example, when the OpenGL Matrix mode is in modeling mode; more on this later). To create a cube, use either of the following:

void glutSolidCube(GLdouble size);
void glutWireCube(GLdouble size);

The size argument is the length of any edge of the cube. To draw a cone, use either of the following:

void glutSolidCone(GLdouble base, GLdouble height,
GLint slices, GLint stacks);
void glutWireCone(GLdouble base, GLdouble height,
GLint slices, GLint stacks);

The base argument is the radius of the cone’s base. The height argument is the height of the cone. The slices argument is the number of flat bands drawn around the z-axis. The stacks argument is the number of flat bands drawn about the z-axis. The center of the base of the cone is placed at X=Y=Z=0 in the modeling coordinate system. The cone “points” along the z-axis. If you want to draw a torus, use either of the following GLUT functions:

void glutSolidTorus(GLdouble inner_radius,
GLdouble outer_radius,
GLint nsides, GLint rings);
void glutWireTorus(GLdouble inner_radius,
GLdouble outer_radius,
GLint nsides, GLint rings);

The inner_radius and outer_radius arguments are the inner and outer radii of the torus. The nsides argument is the number of flat bands drawn for each radial section. The rings argument is the number of radial bands.

Posted on: 18/12/2009








0 Comments
If you want to leave a comment please Login or Register