Throughout the semester, we will have several labs. You are required
to save some of your files on the hard disk or on a floppy disk. If
you do not save the images resulting from a run, the programs do not take
up too much space. Please bring at least one floppy disk with you to
keep a backup copy of your files. also, if you plan to work on a program
from home, you can use ftp to transfer your file(s) to cs so you can
access them from home or other places. Please use ASCII mode when you
move your C++ files around, otherwise you will get an ^M at the end of each
line, which is pain in the neck to remove.
It is very important that you complete and run your programs on the hard disk. The executable files take a good bit of disk space and can not be run from the floppy. For this to work best, you may need to sit at the same machine every time we come to the lab. This way you can create a directory with the same name as your ID on cs and keep it until the end of this semester.
1) Create a directory for yourself, best is
to call is YourID,
2) Create the lab1 directory for today's lab.
In order to run OpenGL programs, we will use Visual C++ compiler which
is installed on the PCs in the PC Lab (Room 439 or Ex-Term Lab). To
run the OpenGL programs, we also need to link some of the OpenGL libraries
in each program that we wish to run. During this lab, we may run to
some problems when we compile the programs. These problems, will
be resolved by including appropriate files in the include or lib
directories. To make sure, we have the library files in place,
here is what you need to do before starting the lab.
First we need to install GLUT onto the computers. The files you will need
are as follows:
To compile an OpenGL programs under .Net:
Use the Build tab, click on Compile, or while you are in the program do Ctrl-F7. If your program does not have any error, you will get:
Build: 1 Suceeded, 0 Failed, 0 Skipped
Please note that it is extremely important that you copy the file under appropriate directory.
A Simple Example: Line Program
Lab Activity (1): Cut an paste the following program into the line.cpp file that you had saved in the previous step. Click on Save to save the changes.
The name of this screen is Test. The line;
gluOrtho2D(0.0, 50.0, 0.0, 50.0);maps world coordinates in the range [0,50] x [0,50] into this window, with (0,0) at the lower left. This is a parallel projection in which the z-coordinates are thrown away. The most significant block of code for the purposes of this lab is
glBegin(GL_LINES);which draws a single line. The "2f" in "glVertex2f"says that we specify points using two floating point parameters. The z-coordinate is assumed to be zero, thus we are working in the a 2D plane, x-y plane.
You can add other lines in the glBegin .. glEnd block; for example,
glBegin(GL_LINES);would draw a big "X".
void display( void )Since you have used the sin and cos functions, you need to add:
glClear(GL_COLOR_BUFFER_BIT); /*clear the window */
glFlush(); /* clear buffers */
#include <math.h>at the top of the program. Recompile and run. You should get part of a circle.
Lab Exercise (2): Change the display code so that the entire circle fits in the window.
Your homework assignment is to further modify the program so that it prints a sine curve (at least two cycles) centered vertically in the window. The result should look something like this:
Submit your source code as an attachment to en e-mail to me (rt) on cs before class on Wednesday, 1/28/04 and turn in a printout of the screen shot at the start of class. Make sure to include a header with your name, course number, and date at the top of your program. If there is any special instructions for running your program, please include it in the header of the program.