From Immersive Visualization Lab Wiki
Revision as of 15:20, 20 October 2018 by Jschulze (Talk | contribs)

Jump to: navigation, search

Project 3: Textures, Scene Graphs and Culling

This page is currently under construction. It will be completed on Oct 20. Feel free to start working on it at any time.

In this project you will need to implement a scene graph to render an army of animated robots with textures on them.

The total score for this project is 100 points. Additionally, you can obtain up to 10 points of extra credit.

1. Applying a Texture (25 Points)

The first step of the project is to texture a robot component so that you can later use it as part of your robot.

Start with code that uses your trackball code, and modify it so that trackball rotations control the camera instead. (If you didn't get that to work, keyboard controls to rotate the camera will suffice.)

Thanks to our tutors Weichen and former tutor Yining, you have the following robot parts to choose from: head, body, limb, eye, antenna. You will find the OBJ files in this ZIP file. Each vertex has not only a 3D coordinate and a normal associated with it, but also a texture coordinate. This allows you to map textures to the surfaces of the robot. Note that unlike the previous obj files in the course, each face has different indices for v/vt/vn. So you are going to need to update your parser accordingly, when you add texture support. One of ways to deal with the different indices is to re-order (and duplicate) the v/vt/vn data when parsing so that their indices align. The following code fragment from "OpenGLInsights" might be useful:

// For each triangle
for( unsigned int v=0; v<vertexIndices.size(); v+=3 )
    // For each vertex of the triangle
    for ( unsigned int i=0; i<3; i+=1 )
        unsigned int vertexIndex = vertexIndices[v+i];
        glm::vec3 vertex = temp_vertices[ vertexIndex-1 ];
        unsigned int uvIndex = uvIndices[v+i];
        glm::vec2 uv = temp_uvs[ uvIndex-1 ];

        unsigned int normalIndex = normalIndices[v+i];
        glm::vec3 normal = temp_normals[ normalIndex-1 ];


Choose one of the robot parts to apply a texture to. Best candidates are the body and the head.

Choose a texture image for the robot part. You can use any non-offensive image you find on the internet through image search, for example, or use a picture from your own collection. Best is to trim and resize it to a size of roughly 512x512 pixels.

Load the image into your C++ code. We provide sample code which loads a PPM image file and uses it as a texture for a quad. If you decide to use an image in a format other than PPM (eg, JPEG), you need to convert it to PPM first. The above mentioned image processing tool IrfanView for Windows will do this for you. Alternatively, you can use a third party library such as SOIL to natively load JPEG images, or other image formats.

Use the following settings for your texture after your first glBindTexture(GL_TEXTURE_CUBE_MAP, id) for correct lighting and filtering settings:

  // Use bilinear interpolation for higher image quality:

  // Use clamp to edge to hide avoid repeating the texture: