#include <GL/glut.h>
#include <stdlib.h>
void display(void) {
glClear(GL_COLOR_BUFFER_BIT); //flush gl
typedef GLint vertex3[2]; //2 attributes
int rows= 3;
int cols= 5;
//data storage matrix
vertex3 vData[rows][cols]= {
{{0,80}, {50,50}, {100,100}, {150,75}, {200,120}},
{{0,50}, {50,100}, {100,80}, {150,150}, {200,60}},
{{0,20}, {50,70}, {100,120}, {150,160}, {200,200}}
};
//set flags
glPushAttrib(GL_ENABLE_BIT);
glEnable(GL_LINE_STIPPLE);
//draw each line
for(int r=0; r<rows; ++r){
//line color, width, type
switch(r){
case 0:
glColor3f(1.0, 0.0, 0.0); //red
glLineWidth(1.0); //single-width
glLineStipple(1, 0x00FF); //dashed
break;
case 1:
glColor3f(0.0, 1.0, 0.0); //green
glLineWidth(2.0); //double-width
glLineStipple(1, 0x0101); //dotted
break;
case 2:
glColor3f(0.0, 0.0, 1.0); //blue
glLineWidth(3.0); //triple-width
glLineStipple(1, 0x1C47); //dash-dot
break;
}
//draw each vertice
glBegin(GL_LINE_STRIP);
for(int c=0; c<cols; ++c){
glVertex2iv(vData[r][c]);
}
glEnd();
}
//clear flags
glPopAttrib();
glFlush();
}
int main(int argc,char *argv[]) {
glutInit(&argc,argv); //prepare glut
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); //set the display mode
glutInitWindowSize (500, 500); //the size of the program window
glutInitWindowPosition (100, 100); //initial position for the window
glutCreateWindow ("CS334-Lab9"); //create window with a title
glClearColor(0,0,0,0.0); //background color
glMatrixMode (GL_PROJECTION); //2d envyronment
gluOrtho2D (-20.0, 220.0, 0.0, 220.0); //matrix dimensions
glutDisplayFunc(display); //show thee actual program
glutMainLoop();
return EXIT_SUCCESS; //exit the program
}
Comments