CMPS-3480 Computer Graphics
Lab-7

Overview:

Step 1:
Change to your 3480/7/ folder.

Copy the lab files now...
cp /home/fac/gordon/p/3480/code/lab7/* .

Compile and run the program:
make
./lab7

Press 5


We will do some coding together to turn the pyramid into
a smooth cone or cylinder.

Get ready to code!

Wednesday in-class texture mapping
We will put a texture on one of the lab7 quads.

OpenGL texture map components
-----------------------------

Do these things one time when the program starts...

1. Allow 2-dimensional texture-map rendering
   glEnable(GL_TEXTURE_2D);

2. Define a texture ID
   GLuint texID;

3. Generate a texture ID
   glGenTextures(1, &texID);

4. Get your data stream of pixels
   use your get_image_stream()
   unsigned char *data = get_image_stream("image.ppm", &w, &h);

5. Bind to the texture ID
   glBindTexture(GL_TEXTURE_2D, texID);

6. Define the texture characteristics
   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
   glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0,
       GL_RGB, GL_UNSIGNED_BYTE, data);

Do these things every time you render the texture...

1. Bind to the texture ID
   glBindTexture(GL_TEXTURE_2D, texID);

2. Indicate a texture coordinate for each vertex
   glTexCoord2f(0.0f, 1.0f);
   glVertex2i(-w, w);

3. Un-bind the texture ID
   glBindTexture(GL_TEXTURE_2D, 0);


Homework
Homework is...

1. Get your cylinder built correctly.

   Build a smooth-looking cylinder using 10 or less points-on-a-circle.

   You will have to give a normal to each vertex rather than each triangle.
   This is called Phong shading.
   It is described in our text books and many articles online.


2. Put a texture on the cube in menu item #6.

   Apply the texture to all 6 sides of the cube.
   Use a texture image that makes sense for a cube.

   I recommend using a texture image that you produced yourself using
   your phone camera and Gimp.


3. Put a texture on your cylinder.

   Apply a texture such as a soda can.
   Make your own texture image.

Do not use any images that are copyrighted or have watermarks.
Making your own texture images is best.

Here is my own textured cylinder made of bricks.
The texture is from the fireplace in my house.

I used just 20 points-on-a-circle.
The texture image dimensions are 1024 x 256 pixels.

Here is my texture image





This is a Phong-shaded cylinder.
Just 12 points-on-a-circle.
No edges are visible on the cylinder's surface.

I will describe Phong shading in class,
then you will add it to your homework.

What to turn in...
Your instructor will find your work out on Odin!