Our goals in this lab are:
* Textlist.cpp -
* This program uses a display list to display Letter O on the screen
* This program demonstrates how to make and execute a
static void myinit (void)
gluOrtho2D(0.0, 20, 0, 20);
glClearColor (1, 1.0, 1.0, 1.0);
listName = glGenLists (1);
glNewList (listName, GL_COMPILE);
glTranslatef(5, 10, 0.0);
glColor3f (1.0, 0.0, 0.0); /* current color red */
for(int i = 0; i <= 12; i++)
angle = 3.14159/6.0 * i;
glVertex2f (4*cos(angle), 4*sin(angle));
glVertex2f (5*cos(angle), 5*sin(angle));
glColor3f (0.0, 1.0, 0.0); /* current color green */
int main(int argc, char** argv)
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
This produces the following screen:
Lab Activity (1)
Modify the above program to create letter Q. Something like what I have shown below. it does not have to be exactly like this, as long as I can tell it is a Q :-). Email your program as an attachment, on the subject line put Activity 1.
Lab Activity (2)
Modify your program to display OQO on the screen. You decide about the size of the and location of the letters. Submit the program for this activity as an attachement. At the Subject Line, write Activity 2.
Reading Object Data from a File
The following program shows how we can read data points from a file then display them.
Copy and paste the program and run it. Since you don't have
the input file, you won't get anything. Create a file called
input.txt and store the data in red font in that file and save the
The file must be saved in the same directory as the .cpp file for this
150.0 250.0 200.0 300.0 1.0 0.0 0.0 2.0
200.0 300.0 250.0 250.0 1.0 0.0 0.0 2.0
160.0 260.0 160.0 130.0 1.0 0.0 1.0 8.0
240.0 260.0 240.0 130.0 1.0 0.0 1.0 8.0
which has the following format:
Number of line = 4 -- This has to follow with four lines each representing one line.
x and y of the start point, then x and y of the end point, then r,g,b for color of the line, and then the width of the line. So the first line starts at x = 150.0 and y=250.0, ends at x = 200.0 and y = 300.0, with r = 1.0, g = 0.0, and b = 0.0 for its color, and width = 2.0.
Now you can run the program to produce the output. It is a
If you run this program using the input.txt file and you will get a screen that looks like this:
Lab Activity (3)
You can use a similar method to draw (plot) the points for a function.
Number of Data Point
An example of input data file for a sin function:
You need to read this file into your program and draw the data
points a Line Strip. Can you tell what the function is? hint
y = ? * x ? + ?
program for this activity as an attachment. At the Subject Line,
write Activity 3.