Advertisement
axyd

lab_9

Mar 28th, 2019
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <GL/glut.h>
  2. #include <stdlib.h>
  3.  
  4. void display(void) {
  5.     glClear(GL_COLOR_BUFFER_BIT);   //flush gl
  6.    
  7.     typedef GLint vertex3[2];   //2 attributes
  8.     int rows= 3;
  9.     int cols= 5;
  10.    
  11.     //data storage matrix
  12.     vertex3 vData[rows][cols]= {
  13.         {{0,80}, {50,50}, {100,100}, {150,75}, {200,120}},
  14.         {{0,50}, {50,100}, {100,80}, {150,150}, {200,60}},
  15.         {{0,20}, {50,70}, {100,120}, {150,160}, {200,200}}
  16.     };
  17.    
  18.     //set flags
  19.     glPushAttrib(GL_ENABLE_BIT);
  20.     glEnable(GL_LINE_STIPPLE);
  21.    
  22.     //draw each line
  23.     for(int r=0; r<rows; ++r){     
  24.         //line color, width, type
  25.         switch(r){
  26.             case 0:
  27.                 glColor3f(1.0, 0.0, 0.0);   //red
  28.                 glLineWidth(1.0);           //single-width
  29.                 glLineStipple(1, 0x00FF);   //dashed
  30.                 break;
  31.             case 1:
  32.                 glColor3f(0.0, 1.0, 0.0);   //green
  33.                 glLineWidth(2.0);           //double-width
  34.                 glLineStipple(1, 0x0101);   //dotted
  35.                 break;
  36.             case 2:
  37.                 glColor3f(0.0, 0.0, 1.0);   //blue
  38.                 glLineWidth(3.0);           //triple-width
  39.                 glLineStipple(1, 0x1C47);   //dash-dot
  40.                 break;                 
  41.         }
  42.        
  43.         //draw each vertice
  44.         glBegin(GL_LINE_STRIP);    
  45.             for(int c=0; c<cols; ++c){
  46.                 glVertex2iv(vData[r][c]);              
  47.             }      
  48.         glEnd();    
  49.     }
  50.    
  51.     //clear flags
  52.     glPopAttrib();
  53.    
  54.     glFlush();
  55. }
  56.  
  57. int main(int argc,char *argv[]) {
  58.     glutInit(&argc,argv);                   //prepare glut
  59.     glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);       //set the display mode
  60.     glutInitWindowSize (500, 500);          //the size of the program window
  61.     glutInitWindowPosition (100, 100);      //initial position for the window
  62.     glutCreateWindow ("CS334-Lab9");        //create window with a title
  63.  
  64.     glClearColor(0,0,0,0.0);                //background color
  65.     glMatrixMode (GL_PROJECTION);           //2d envyronment
  66.     gluOrtho2D (-20.0, 220.0, 0.0, 220.0);  //matrix dimensions
  67.  
  68.     glutDisplayFunc(display);               //show thee actual program
  69.     glutMainLoop();
  70.  
  71.     return EXIT_SUCCESS;                    //exit the program
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement