BU
CAS
CS 480
Introduction to Computer Graphics
Spring 1996
Programming Assignment 1
Due before class on Tuesday, February 6
This programming assignment will get you started as an OpenGL
programmer, while introducing you to basic concepts in interactive
graphics programming. You will develop a polygon drawing tool that
allows the user to draw, fill, and modify a polygon given mouse and
keyboard input. Since this is the first assignment, code templates and
example programs are provided.
The polygon editing tool must run on the SGI, therefore you will need
to use one of the SGI workstations in the CGL cluster (unless you have
access to an SGI workstation elsewhere).
Your program's source files are to be electronically submitted by using the submit program on cgl. The code you submit
should conform with the program assignment
guidelines.
Part of your grade for this programming assignment will be based on
your giving a short demo (2-3 minutes) in the CGL cluster. You will
be expected to talk about how your program works, and we will see
how well your program performs on some test examples. A demo date for
this assignment is not yet scheduled but will be announced in class
this Thursday, January 30. You will be asked
to sign up for a slot by next Thursday.
Get Some Files
To help get you started, some source files and templates
have been provided. Some basic graphics utilities and the polygon tool's main
program are provided for you. So, before you begin programming, you will need
to copy some files from the directory /usr2/cs480/courseware/p1
on the CGL cluster. These files are:
By copying the source files, you have almost everything you'll need to
build your own polygon drawing program. You are expected to complete
the program by providing two missing subroutines using the code
templates and by adding new callbacks. There are comments in the two
template files that will help guide you in writing your own
subroutines.
Example Program
There is an example polygon drawing program poly included in
the same directory as the source files. This example demonstrates how
area fill works when the OpenGL general polygon capabilities are used.
Notice that concave and self-intersecting polygons are not always
correctly handled. General polygons must be subdivided into convex
polygons in order for OpenGL to draw them correctly.
The Code You Write
You are expected to write two new routines based on the templates provided
in the files wire.c and fill.c , in addition you
add new functionality to the program.
-
In wire.c write a subroutine that calls the appropriate
OpenGL routines to first draw a closed polygon's edges in the edge
color, and then draw the polygons's points in the point color. If
there are more than two points, then the polygon should be drawn
closed.
-
In fill.c write a modified scan-line polygon fill subroutine
based on the algorithm described in the text on pages 117-125. Rather
than scan-converting the polygon, your subroutine should generate a
series of quadrilaterals and triangles as described in class, and as
illustrated in the fill.c code template.
- Add the following new functionality to your program
- Setup keyboard control for: increasing and decreasing line width
(suggestion, use arrow keys for input control).
- Setup up keyboard control for toggling of OpenGL antialiasing.
- Change the colors used in your program to suit your own taste
while also satisfying visibility constraints.
Extra Credit
For extra credit, change your program to allow texture mapped area
fill. You will find an example OpenGL program showing the use of
texture mapping in /usr2/cs480/courseware/book/checker.c.
Be sure to create your own texture.
The user should be able to toggle texture mapping
on and off by using the T key.
It possible to make the texture stretch as you pull the polygon,
or to make it stay fixed. It depends on what values you send into
the
CS480 class Home Page for links to online OpenGL documentation.
The following is a partial list of OpenGL routines you will probably need
to do the compulsory part of this assignment:
- glBegin
- glClearColor
- glClear
- glColor
- glFlush
- glGetIntegerv
- glLoadIdentity
- glMatrixMode
- gluOrtho2D
- glPointSize
- glVertex
- glViewport
- glXSwapBuffers
Hint 2: Example OpenGL Programs
Many example programs from The OpenGL Programming Guide
(red book) are available on the CGL cluster in /usr2/cs480/courseware/book.
Hint 3:
There are copies of the The OpenGL Programming Guide
(red book) available for loan in the CGL cluster technical consulting office.
Page Created: Jan 20, 1996
Last Modified: Jan 11, 1996
Maintained by: Stan Sclaroff