Advertisement
sohag_cse

Lab Task - 03 (182-15-2164-PC-A)

Oct 16th, 2021
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GL/glut.h>
  2. #include <stdio.h>
  3. #include <GL/gl.h>
  4. #include <math.h>
  5.  
  6. void init(void)
  7. {
  8.     glClearColor(0.0,0.0,0.0,0.0);
  9.     glMatrixMode(GL_PROJECTION);
  10.     glLoadIdentity();
  11.     glOrtho(0.0, 500.0, 0.0, 500.0, -1.0, 1.0);
  12. }
  13.  
  14. void Draw()
  15. {
  16.  
  17.     int xs=21, ys=87, xe=387, ye=321;
  18.     double xi, yi, m;
  19.     glClear(GL_COLOR_BUFFER_BIT);
  20.     glColor3f( 0,1, 0.5);
  21.     m = (ye-ys)/(xe-xs);
  22.     if(xe>xs){
  23.         if(m<=1){
  24.             xi = 1;
  25.             yi = m;
  26.         }
  27.         else if(m>1){
  28.             yi = 1;
  29.             xi = 1/m;
  30.         }
  31.     }
  32.     else if(xs>xe){
  33.         if(m<=1){
  34.             xi = -1;
  35.             yi = -m;
  36.         }
  37.         else if(m>1){
  38.             xi = (-1)/m;
  39.             yi = -1;
  40.         }
  41.     }
  42.     glBegin(GL_POINTS);
  43.     glVertex2i(round(xs), round(ys));
  44.  
  45.     while(1){
  46.         xs = xs+xi;
  47.         ys = ys+yi;
  48.  
  49.         glVertex2i(round(xs), round(ys));
  50.  
  51.         if(xs==xe || ys==ye){
  52.             break;
  53.         }
  54.     }
  55.  
  56.     glEnd();
  57.  
  58.     glutSwapBuffers();
  59. }
  60.  
  61. int main(int argc,char **argv)
  62. {
  63.     glutInit(&argc,argv);
  64.     glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE );
  65.     glutInitWindowPosition(0,0);
  66.     glutInitWindowSize(500,500);
  67.     glutCreateWindow("Sohag Raha - 182-15-2164");
  68.     init();
  69.     glutDisplayFunc(Draw);
  70.     glutMainLoop();
  71.     return 0;
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement