Project5Fall14

From Immersive Visualization Lab Wiki
Revision as of 16:29, 14 November 2014 by Jschulze (Talk | contribs)

Jump to: navigation, search

Project 5: Light and Shade

THIS PAGE IS UNDER CONSTRUCTION - PLEASE DO NOT YET START WITH THIS PROJECT

This project is on OpenGL lighting and shading, and includes GLSL shader programs.

This project is due on Friday, November 21st at 3:30pm and will be discussed in CSB 001 on Monday, November 17th at 5pm.

Notes:

  • GLSL shaders will be covered in class on Tuesday, November 18th.
  • This project does not require a scene graph data structure. But we encourage you to use your scene graph for this and the remaining projects because it can make your code easier to write and debug.

1. 3D Model Loader

OBJ files are 3D model files which store the shape of an object with a number of vertices, associated vertex normals, and the required connectivity information to form triangles. Wikipedia has an excellent page on the OBJ file format. The file format is an ASCII text format, which means that the files can be viewed and edited with a text editor.

Here are three files for you to work with:

The files provided in this project only use the following three data types (other OBJ files may support more):

  • v: 'vertex': followed by six floating point numbers. The first three are for the vertex position (x,y,z coordinate), the next three are for the vertex color (red, green, blue) ranging from 0 to 1. Example:
    v 0.145852 0.104651 0.517576 0.2 0.8 0.4
  • vn: 'vertex normal': three floating point numbers, separated by white space. The numbers are for a vector which is used as the normal for a triangle. Example:
    vn -0.380694 3.839313 4.956321
  • f: 'face': lists three sets of indices to vertices and normals, which are the three corners of a triangle. Example:
    f 31514//31514 31465//31465 31464//31464

Lines starting with a '#' sign are comments and can safely be ignored.

Write your parser so that it goes through the OBJ file, line by line. It should read in the first character of each line and based on it decide how to proceed. Lines with parameters can be read with the fscanf command. Here is an example for vertices:

FILE* fp;     // file pointer
float x,y,z;  // vertex coordinates
float r,g,b;  // vertex color
int c1,c2;    // characters read from file

fp = fopen("bunny.obj","rb");
if (fp==NULL) { cerr << "error loading file" << endl; exit(-1); }

c1 = fgetc(fp);
c2 = fgetc(fp);
if (c1=='v') && (c2==' ')
  fscanf(fp, "%f %f %f %f %f %f", &x, &y, &z, &r, &g, &b);
// parse other cases and loop over lines of file

fclose(fp);   // make sure you don't forget to close the file when done