CS465, Computer Graphics, Fall 2012

Programming Assignment # 1

Drawing Geometric Objects with GLSL

Demo Date: November 1, Thursday, 2012, Class Hour (13:40), in EB204

This assignment will NOT be done in groups. Every individual student should do his/her homework.

Demo will be at class hour in one of the labs in the new building. Every student is required to be in the demo.

1. Introduction

This assignment requires you to design and implement a basic graphics program that draws a 3D geometric object on the screen. This will be an interactive program that allows the user to choose the object to draw (from a choice of 5 objects), to choose various drawing attributes for the object (such as color), to rotate and zoom on the object. Each time the user selects one of the drawing options the image on the screen will be redrawn with the new choices. To develop this program you will need to learn to use both the OpenGL, and FreeGLUT graphics libraries. The FreeGLUT library includes functions for implementing event-driven input and display handling operations. This program will be an introduction to developing event-driven graphics programs. The program must be developed using C++.


2. Learning Objectives:

3. Problem Specification

Design an interactive graphics display program that draws geometric objects. The program will draw one of 5 different shapes interactively chosen by the user, and it will let the user select:

Your program must handle user input from the keyboard and the mouse, set the drawing modes as specified  below, and display results determined by the currently selected drawing modes in a window on the  screen.

3.1. Configurable Attributes

Object type and drawing mode (wireframe or solid) must be set through pop-up menus created by FreeGLUT library functions. You must create a hierarchical pop-up menu with three-menus (object type, drawing mode and color) each poping up to related submenu entries. 

3.2. Keyboard Interface

Your program must also properly handle the reshape event; so you must define your own reshape callback function.

4. Program Requirements

  1. IMPORTANT! Your application must use OpenGL Shader Language(GLSL) and make use of GLSL Vertex and Fragment Shaders. Programs implemented with Fixed Function OpenGL calls will not be graded( that means no calls to functions like glBegin() or glVertex(..) ).
  2. You must design this program as an event-driven main application that responds to keyboard, mouse and reshape events. Thus, you should follow the main program and function module model given in Edward Angel's book and lecture slides. (you can find the source codes and other supporting material for the book Edward Angel, Interactive Computer Graphics: A Top-down Approach, Sixth Edition, here.     
  3. Your program files must have documentation comments.

    Your program will be graded for:

  4. You are required to run your program and demonstrate that it works.

You are required to submit only the source files, i.e. the project files, ready to be compiled and run. Please try to comply with the announced due date. You can send the files via e-mail to your TA.

5. Implementation Hints

  1. Detailed documentation for OpenGL functions are described in your textbook and the OpenGL Programming Guide.

  2. Use the FreeGLUT (Free GL Utility Toolkit) library functions as described in your textbook. There is a WWW user manual at http://www.opengl.org/documentation/specs/glut/spec3/spec3.html. You will need to read about functions in Sections:

  3. All your source files must have the statement #include <freeglut.h> . There is no need to include <GL/gl.h> or <GL/glu.h> since freeglut.h contains #include statements for these two header files.

  4. You need global variables that hold state values for your program, e.g., a code number for the current object type to draw, a code value for the current draw mode (wire frame or solid), and possibly other values. The callback functions should merely assign a new value in your global data structure. Then the display() function will read the current state values to determine what object to draw, how to draw it, etc. Note, we are forced to use global data even though that is not good software design because of the way the FreeGLUT library software designers specified the  input callback functions.   

  5. The various drawing mode control options listed above (type of object, draw mode, color) should be handled by using these FreeGLUT lib functions:

    Each of these functions must be called one time at program initialization  with a parameter that is the name of your callback function. Your actual callback functions must have the appropriate prototype.

    You are welcome to design your own user input technique for setting these state variable values with some other combination of key inputs or with mouse inputs (if you define a mouse callback function and call glutMouseFunction() or glutMotionFunction()).


  6. Your object #5 must be as defined in the file anyi.dat.

    Dat file:

    A text file in which the geometry information is encoded in the following order:

     

    Number of faces (int)

    Number of vertices (int)

    List of vertices (each entry has 3 float x,y,z coordinate values)

    Face index list (each entry has 3 integer vertex indices (oriented))

     

    Each line in the face index list has 3 indices that define a triangle of the surface. The index i corresponds to the i th vertex of the vertex list in the appearance order. Your program has to read the  file and appropriately place the data into arrays before drawing operations(See examples in Section 2 of your textbook). Since this is a text file, you can view its contents with a text editor if you wish.


  7. To handle rotation of your objects, include in your global data structure an X rotation angle variable (xRot) and a Z rotation angle (zRot) variable (both initialized to 0.0). Then use the following keyboard keys in your special key callback function (glutSpecialFunc()):

  8. To handle zooming on your objects, include in your global data structure a scale factor variable (scaleFactor, initialized to 1.0). Then use the keyboard keys z and Z in your keyboard callback function (glutKeyboardFunc()) to multiply the current value of scaleFactor with 1.1 (zoom-in) or 0.9 (zoom-out).

  9. For this assignment you'll use the predefined model,view and projection (MVP) transformation matrices. You'll pass these matrices as uniform variables to your vertex shader. display() function should use the following OpenGL calls.
    
      
            void display(){
              glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
              model_view = LookAt(eye,at,up) * RotateX(xRot) * RotateZ(zRot);
              projection = Ortho(VIEW_LEFT,VIEW_RIGHT, VIEW_BOTTOM, VIEW_TOP, VIEW_NEAR, VIEW_FAR );
              glUniformMatrix4fv(matrix_loc, 1, GL_TRUE, model_view);
              glUniformMatrix4fv(projection_loc, 1, GL_TRUE, projection);
              glDrawArrays(GL_TRIANGLES, 0, N);
              glutSwapBuffers();
          }
      The details on how these model-view and projection matrices are formed will be discussed later in the course. Briefly, what they do is:
  10. IMPORTANT!!!... For implementation details please refer to the online resources of the Angel's textbook. Codes for the textbook examples are provided at this link. You may check the examples given for chapter 4 in CHAPTER04 folder. The definitions of the methods such as LookAt(...),RotateX(...),RotateZ(...) and Ortho(...); common linear algebra operations; and vector and matrix data structures are provided in the include directory.(check mat.h and vec.h files).

  11. You may use all of the textbook resources(including the example code, slides etc.) given that you provide in-text references in your documentation. You can also refer to the online tutorials given at the Assistant's Website.

  12. If you have any questions feel free to ask your assistant with an e-mail. You may also schedule a visit to your assistant at his/her office during the office hours.

  13. This assignment is not hard but it will require much effort and patience to complete. You have 4 weeks to finish the assignment hence START AS EARLY AS POSSIBLE!.

  14. DO NOT TRY TO BE A LAST NIGHT HERO!... as you'll most likely to fail the assignment if you do so.


  15.