CS 373 Project 1: Using OpenGL and GLUT

Due Friday, September 15, 2006

Introduction

This is a simple project to help familiarize you with our graphics hardware and software. You will learn how to edit and compile programs on our workstations and you will begin to learn how to use both OpenGL and GLUT to build graphics applications.

Assignment

Write a program using OpenGL and GLUT to draw a simple picture of a house using an instructor-supplied program as a template.

Getting started

Download the file box.cc by holding the shift key while left-clicking on the link for the file. Choose "Save link as" (or something similar if you're not using FireFox as your browser) to save the program.

I will want you to work on your projects in specific directories on the workstations; for this project that will be ~/cs373/p1. You may, of course, work on the program elsewhere as well, but when you've finished the project you must leave a copy of the source code and the executable in the ~/cs373/p1 directory.

Open a terminal shell and type

        mkdir -p cs373/p1

to create the necessary directory. Now type

        mv box.cc ~/cs373/p1

to move the program you've just downloaded to the proper directory then type

        cd cs373/p1

to change to that directory. To compile the program, type

        smake box.cc

press Enter and the program will be compiled. (Smake is a local program that carries out the commands listed in the $Smake: line at the top of the program source file. It is useful because it saves a lot of typing and lets you put the correct compilation command right in the source file. This is very nice when you want to compile something that you wrote a while back and don't remember the exact compilation command.)

Now run the program by typing

        ./box

and pressing Enter. A back window with three squares should pop up. When you are done, press q or the ESC key to quit the program.

Go back and look at the program source code again and make sure that you can figure out what each part of the program is doing. You can print the program with the command

        lpr box.cc

and then connecting to https://printercontrol to authorize printing the file. The printer is located in MacDonald 110, the Introduction to Computer Science laboratory.

Now edit the file and try making small changes to the source, saving the source file, reissuing the smake command and rerunning the program to see the effects of the changes. Don't worry about changing your copy of the source, you can always get a fresh copy as described above.

Moving along

Now for the main part of your first project. Copy the source code for the box program to the new file house.cc:

        cp box.cc house.cc

Using the figure

(also available as a PDF file) as a plan, edit the file house.cc to create a computer program using GLUT and OpenGL that draws a picture of a house on the screen. Actually, all you need to do is change the body of the drawBox() function (you may want to change it's name as well) to draw the outline of the house, the door, windows, window boxes and the chimney. Your program should draw all the lines exactly as they appear on the plan (you don't need to draw the background grid). Pay special attention the coordinates of the points, especially those around the chimney. Feel free to experiment with different colors for the lines in your drawing.

If you're looking for ideas and examples, here are some student projects from previous years.

Finishing Up

Please determine the answers to the following questions:

  1. What is the difference between calling glBegin() with GL_LINE_STRIP and GL_LINE_LOOP?

  2. How could the amount of code necessary to draw the two windows be reduced?

  3. What happens if you change the default color between two calls to glVertex()? (Try it and see.)

Please enter your name:          

If you're anxious to try something else, change one of your GL_LINE_LOOP arguments to GL_POLYGON so that a solid polygon is generated. Can you make a nice picture of the house with solid polygons? How will you get the windows to look nice (i.e., have dark backgrounds, etc.)?

What you should turn in