OpenGL 3:

 

The objective of this lab is to introduce you to “GLU” objects, error handling, and texture mapping.

 

  1. OpenGL does not provide support for 3D objects but, fortunately, there is a utility library called “GLU” that does.   The third openGL lab shows how to create a sphere using GLU.  The primary steps are
    1. Create a handle for the object with a gluNewQuadric() call.  The handle is a GLUQuadricObj*.
    2. Create the sphere with a gluSphere(sphereHandle, radius, stacks, slices) call.

The “resolution” of the sphere is controlled by the stacks and slices parameters.  When you are done with the sphere call glDeleteQuadric(sphereHandle).

 

  1. When OpenGL encounters a problem it sets an error flag.  The third OpenGL lab checks for errors in the Render routines. 

 

  1. The main steps in texture mapping are to

 

    1. Create a texture object.
    2. Specify how the texture is to be applied to each pixel
    3. Enable texture mapping
    4. Draw the scene, supplying both texture and geometric coordinates for vertices.

 

You should download opengl3.cpp, bmp.cpp, bmp.h, and myTexture.bmp.  Create a new win32 application, insert these files, and build an executable.  The program creates a scene with a red sphere and a texture mapped triangle.

 

What you should do:

1.      To texture map the sphere you should

a.       Add   gluQuadricTexture(theSphere,GL_TRUE);  just before the glueSphere call in BuildSphere().

b.      Enable textures before the sphere is drawn in Render().

 

2.       GLU supports a variety of 3D objects and you should try them out.  Following are the function prototypes

a.       void gluCylinder(GLUquadricObj *qobj, GLdouble radius,

GLint slices, GLint stacks);

b.      void gluDisk(GLUquadricObj *qobj, GLdouble innerRadius,

GLdouble outerRadius, GLint slices, GLint rings);

c.       void gluPartialDisk(GLUquadricObj *qobj, GLdouble innerRadius,

GLdouble outerRadius, GLint slices, GLint rings,

 GLdouble startAngle, GLdouble sweepAngle);

3.      You can also change the drawing style for these objects using gluDrawStyle(GLUquadricObj *qobj, GLenum drawStyle); where drawStyle is a GL enumerated type:  GLU_POINT, GLU_LINE, GLU_SILHOUTTE, GLU_FILL.  Try each of these styles.