Asg 6: Texture mapping

Objectives

In this assignment, we do not need either of the Camera or AW objects. Instead, we will need the PIL Python module (make sure you have this installed on your computer, it may be called Pillow, e.g., py27-Pillow. Using PIL, we will

Assignment

  1. We will not need either of the aw.py or camera.py modules.
  2. You can remove these lines frokm gldraw.py
    from camera import Camera
    from aw import AW
    	
    and replace them with
    from PIL import Image
    	
  3. You can remove all of the following globals
    global rotating
    global x_angle, x_delta
    global y_angle, y_delta
    global prev_x, prev_y
    global camera
    global aw
    	
    and replace them with
    global texName
    	
    Initialize texName = None in the main() function (remember it is a global).
  4. In the init() function
    1. use the global texName and set it via
        texName = glGenTextures(1)
      	
    2. Read in an image using PIL
        # read in texture
        img = Image.open("mandrill.png").rotate(180).transpose(Image.FLIP_LEFT_RIGHT)
        (imw, imh) = img.size
      	
    3. Map the texture to OpenGL's texture memory
        # map texture
        glBindTexture(GL_TEXTURE_2D,texName)
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP)
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP)
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
        # target, level, internalFormat, img.w, img.h, border, format, type, texels
        glTexImage2D(GL_TEXTURE_2D,
                     0,
                     GL_RGBA,
                     imw,imh,
                     0,
                     GL_RGBA,
                     GL_UNSIGNED_BYTE,
                     img.convert("RGBA").tobytes())
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
      	
    4. Turn on texturing
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_BLEND)
      
        glEnable(GL_TEXTURE_2D)
      	
  5. In the display() function
    1. change
        gluPerspective(65.0, 1.0, 1.0, 1000.0)
      	
      to
        w = glutGet(GLUT_WINDOW_WIDTH)
        h = glutGet(GLUT_WINDOW_HEIGHT)
        gluOrtho2D(0.0,w,0.0,h)
      	
    2. draw a simple quad with normalized texture coordinates
        # render
        glBegin(GL_QUADS)
        glTexCoord2f(0,0)
        glVertex2i(0,0)
      
        glTexCoord2f(1,0)
        glVertex2i(w,0)
      
        glTexCoord2f(1,1)
        glVertex2i(w,h)
      
        glTexCoord2f(0,1)
        glVertex2i(0,h)
        glEnd()
      	

Details

  1. There is no computation to be done in this assignment per se, texture mapping mainly requires reading in an image, extracting the image pixels, and transferring them to texture memory.
  2. As there is no camera or 3D object to manipulate, you can strip the program of most of that functionality, e.g., no need to initialize any of the variables pertaining to object rotation, no need to initialize objects aw, camera. Those should all be removed.

Requirements

  1. Your code should be able to display the mandrill.png image.

Turn in

Turn in all of your code, in one tar.gz archive of your asg##/ directory, including:
  1. A README file containing
    1. Course id--section no
    2. Name
    3. Brief solution description (e.g., program design, description of algorithm, etc., however appropriate).
    4. Lessons learned, identified interesting features of your program
    5. Any special usage instructions
  2. source code (.py source)

How to hand in

See handin web page

Grading scheme