Project 1:
Rendering 3D Objects Using OpenGL and GLUT
Fall 2005, CS
354, Computer Graphics
Assigned: September 6,
2005
Due: September 27, 11:59pm
Goal
In this project you shall draw simple objects in three dimensions and modify
their rendering and view, as you change parameters using a keyboard and a mouse.
You shall learn about the graphics library OpenGL and also about GLUT, an
OpenGL user interface toolkit.
Project Specifications
The starter code that has been provided implements a canvas that allows the
user to switch between various rendering modes for various objects. The
starter code already has support for rendering a unit cube using three
different methods. For this project, you will be adding to the
functionality of the canvas so that it can render a cone using three analogous
methods, as well as rendering the cone from a user-controllable triangulation,
and finally rendering more complex 3D objects.
For grading purposes, your program should compile
and run on the
Getting Started
Download the zip file for the starter code and
use the "unzip" command. The program is written in plain C,
although you may want to rename the .c files to .cpp if you are more
comfortable using C++. If you are using a machine with graphics hardware
(such as the ones in
Keyboard Commands
Keyboard commands are interpreted by the
function myKeyHandler() in canvas.c.
d - switch
display modes (the Modes listed here are, in order, Display Mode 1, Display
Mode 2, etc.):
Items 1 - 3 are already
implemented in the starter code as a programming reference and should not need
to be changed. Items 4-9 will be implemented for this project.
D - go
through the display mode list backwards.
s - toggle display styles between solid and wire frame. Solid and
wire-frame styles apply only to GLUT-based display modes
S - same as s
, and < - rotate the model along its x axis
. and > - rotate the model along its y axis
/ and ? - rotate the model along its z axis
= and + - zoom in and out
c - reset the model to its original orientation and zoom
t - run the Performance Test for the current display mode. The
test returns the number of seconds needed for rendering 3 rotations of the
model.
z - restore the window to its default size. (Needed before running
the Performance Test for controlled testing).
q - quit the program
Mouse Commands
left button - Hold, then move the mouse to control rotations about the
model's y-axis and x-axis
middle button - Hold, then move the mouse to control rotations about the
model's y-axis and z-axis
right button - Hold, then move the mouse to zoom in and out
This program uses the OpenGL graphics library to draw to the screen and the
GLUT window manager for the user interface. Try to understand how the interface
is being made in the main() function in canvas.c. Next, try to understand
how the different cubes are being displayed using various OpenGL and GLUT
functions. The cube in Display Mode 1 is being sent directly to the
renderer by either the function glutSolidCube() or glutWireCube(). Refer to an
OpenGL reference book or to the links provided at the end of this document to
understand what the various functions are doing. For this project, you may
ignore lighting and shading functions.
A Note on VRML2.0
VRML2.0(Virtual Reality Modeling Language)
is used to specify 3D geometric objects. For this assignment, Display
Mode 8 uses data extracted from VRML files for a cube, dodecahedron,
icosahedron, and pyramid. You will not be using actual VRML files in this
assignment, but rather, the data extracted from VRML files. The 4 objects
just mentioned will be collectively referred to as VRML objects.
Programming Checklist
The following is a a list of what needs to
implemented in this project.
Code Map
canvas.c - Handles basic GLUT initialization, keyboard input, camera
control, and window resizing and reshaping.
drawing.c, drawing.h - Handles the drawing algorithms for each display
mode and contains the raw data (vertex array, index array, color array) for
cubes and cones. New display modes should be implemented here.
vrml.c, vrml.h - Handles the drawing of vrml objects and contains their
raw data. The various components of the vrml display mode should be
implemented here.
mouse.c, mouse.h - Handles mouse input. These files should not
need to be changed.
Makefile - standard Unix makefile (not used if you are using Visual C++)
README - answers to questions in the Coding (team) portion of Project 1
project1.txt - answers to questions in the Written (individual) portion
of Project 1
Written Questions for Each Team Member (20% of the project grade)
Each team member should write up the answers to these questions on their own
and submit their work separately, as described in the next section.
1.
What are advantages and disadvantages of having vertices explicitly as opposed to
vertex indices in object representations ?
2.
How many matrix modes are there in OpenGL and what are their use ?
3.
What are the differences between view-ports and the viewing frustum?
4.
What is the role of GLUT, and where in OpenGL do you use it ?
5.
What are the differences between a single frame buffer and a double frame buffer?
6.
The line equation representation y=mx+b is not good for displaying a line on the
screen, why?
What and How to Submit
Your program should compile and run on the Taylor or Painter basement machines.
Once you have verified this, submit the following files:
Makefile
Source code (.c and .h files)
README
The README file should be a plain text file and it
should clearly contain: the names of everyone in the Group, an ASCII table of
the Performance Test results (please do NOT use the tab character in your
table), and the answers to the Performance Test questions. In addition,
if appropriate, you may also write about what extra things you did for the
project, any special compilation instructions, what new ideas you came up with,
etc; please keep such a discussion short and to the point.
Change into your source code directory and submit
using:
turnin -submit smpark cs354_project1_code *
to submit everything in the directory, or replace
* with the names of the specific files and directories you wish to
submit. Please submit only one copy of the code for each group (it does
not matter which group member submits the code).
For the answers to the "Written Questions for
Each Team Member", each team member should independently work on and write
up the answers in a file called:
project1.txt.
The file should also be a plain text file which
should contain the answer to the above "Written Questions for Each Team
Member." This is the only file that needs to be submitted for the
Written portion of Project 1.
Each team member will need to submit his or her
own writeup file using:
turnin -submit smpark cs354_project1_written project1.txt
Here is a short note on how to use the
"turnin" program.
Refer the "Grading" section in the
Syllabus
on the course home page for grading and late policy.
Helpful OpenGL and GLUT References
Neider, Davis and Woo, "OpenGL Programming Guide" Second Edition,
Addison-Wesley
OpenGL Online Quick Reference by David Mount (be
sure to read about the OpenGL Basic Drawing section, paying attention to the
glBegin() function)
http://www.cs.umd.edu/users/mount/427/OpenGL/ogl_ref/ogl_ref.html
GLUT Online Tutorial (see Introduction->Setup,
Introduction->Initialization, Introduction->Animation, and
Input->Keyboard).
http://www.lighthouse3d.com/opengl/glut/