CS 551: Introduction to Computer Graphics
Assignment #4
Goal: Implement Phong lighting for directional and point light sources.
Assigned: Thursday, April 6, 2000
Due: Tuesday, April 18, 2000
Relevant reading/files/software:
Synopsis: Your program will load a polygonal object and use OpenGL to render it. You will disable OpenGL lighting and write code to perform your own lighting calculations, applying the Phong lighting model that we discussed in class to the objec
t vertices. You must support at least 2 directional and 2 point light sources. You will need to design a form in fdesign that contains:
- An OpenGL canvas in which to display the object (name this canvas myCanvas).
- An XForms "file selector" object to specify the .poly file to be viewed.
- Controls for setting the position, direction, and intensity coefficients (i.e., color) of the lights, as well as whether the lights are directional or point sources.
- Controls for setting the reflectivity coefficients (ka's, kd's, ks's) of the object.
- A control for setting whether the V vector (from point being illuminated to eyepoint) is constant…i.e., the "infinite viewpoint" hack.
- A button to toggle which direction surface normals point (i.e., interior or exterior)
- A "Quit" button.
As usual, the single best assignment (measured by ease of use and "extra" features) will earn an 11 (one point extra credit).
Turning in the assignment: Before class starts on
Tuesday, April 18, you should:
- Verify that your code compiles and runs correctly on sgi-1.unixlab.virginia.edu. We will use this machine for compiling all assignments.
- Write a README file with your login, your name, what you did, and anything you'd like us to notice or know about your demo.
- Verify that the line in your Makefile beginning "SUBMIT =" includes all relevant files. This includes all source code (including header files!), fdesign form files (.fd suffix), your README, and the Makefile itself. You should not include objec
t (.o) files, libraries, or the final executable.
- Type "make submit" in the directory containing your code. You will get mail in return from the CS551 account with a list of the files that were successfully received.
- If you submit the assignment multiple times be aware that we will only see the last attempt.
Specifics: We are providing the usual Makefile, a C file named gfx.c, which contains code to draw into an Xforms glCanvas, and a header file gfx.h, which contains prototypes for the
functions in gfx.c. As usual, you will modify the functions in gfx.c, adding code to draw the scene and handle callbacks. You will also create a form in fdesign. Saving that form (as a .fd file) will also create .c and .h files that contain the Xf
orms library code for creating the form, which you must include in your program via the Makefile. Some special things to notice about the code:
- Your code will need to create a global variable pointing to your form. This pointer is returned from the
create_form_* call; the Xforms documentation has details. To mak
e the code in gfx.c work correctly you must name this variable myForm. Your form must include a glCanvas object, which you must name myCanvas.
- Gfx.c contains a function called
canvas_expose() which will redraw the canvas when it is created or covered and exposed by another window. After the create_form_* call, you must attach this function to your canvas with the li
ne:
fl_add_canvas_handler(myForm->myCanvas,Expose,canvas_expose,0);
- Here are some models in the .poly format. The horse has inconsistent polygon orientation and may look strange--debug on simpler models.
- Perform lighting calculations at each vertex and use OpenGL's built-in Gouraud shading [glShadeModel(GL_SMOOTH)] to interpolate the resulting colors across the polygon.