Week 9 Tutorial

Question 1: Texturing

  1. What is a reason to use texture mapping rather than lots of little polygons? Are the two representations functionally equivalent? What are the differences?
  2. What is difference between the following 2 texture filter settings?
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
    
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    
  3. What are Mip Maps? Why are they used?
  4. What do the following settings do?
    float flargest[] = new float[];
    gl.glGetFloatv(GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, fLargest[0]);
    gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_ANISOTROPY_EXT,fLargest[0]);
    

Question 2: Texture Co-ordinates

Assuming texture co-ordinates start at 0,0 in the bottom left of the image, define texture co-ordinates for the following situations.
  1. A quad with the following vertices, where you want to map the whole texture to the quad.
        gl.glVertex3d(-1, -1, -1.0);
        gl.glVertex3d(1, -1, -1.0);
        gl.glVertex3d(1, 1, -1.0);
        gl.glVertex3d(-1, 1, -1.0);
    
  2. The same quad but where you want to map the whole texture to the quad in the y-direction, but have 3 repeated copies in the x direction. Assuming we are using GL2.GL_REPEAT mode.
  3. The triangle
        gl.glVertex3d(-10.0, -10.0, 0.0);
        gl.glVertex3d(10.0, -10.0, 0.0);
        gl.glVertex3d(0.0, -5.0, 0.0);
    
  4. The sides of a cylinder where the cylinder containing NUM_SLICES slices as specified below
     
        gl.glBegin(GL2.GL_QUAD_STRIP);{
        for(int i=0; i<= NUM_SLICES; i++){
            double angle = i*angleIncrement;
                            
            double xPos = Math.cos(angle);
            double yPos = Math.sin(angle);
                           
            gl.glNormal3d(xPos, yPos, 0);
                           
            gl.glVertex3d(xPos,yPos,zFront);
                            
            gl.glVertex3d(xPos,yPos,zBack);
    
        }
        }gl.glEnd();
    
  5. The same cylinder but assuming we only want the texture to be like a label covering just one third of the curved surface.

Question 3: Vertex Buffer Objects and Texture Co-ordinates

Suppose you have the following code setting up a VBO for a quad.
private float vertices[] = { -10,0,0,
                              10,0,0,
                              10,10,0,
                              -10,10,0
                           };

private FloatBuffer vertexBuffer = Buffers.newDirectFloatBuffer(vertices);

public void init(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();
        //do init stuff
        //etc
   
        bufferIds = new int[1];
        gl.glGenBuffers(1,bufferIds,0);

        gl.glBufferData(GL.GL_ARRAY_BUFFER,vertices.length*4,vertexBuffer,GL2.GL_STATIC_DRAW);
}

public void display(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();
        //do display stuff
        //etc

       //draw the quad
}
  1. What code would you have to add to the display function to draw the quad?
  2. What would you have to modify/add to include texture co-ordinates in the VBO?

Question 4: Assignment

If there is any time left, discuss the assignment. Please make sure you ask any questions about the format of the json file and in particular the representation of the terrain. That is the most important thing in the early stages of the assignment.