Advertisement
sohag_cse

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

Nov 27th, 2021
1,256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GL/glut.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. void initOpenGl()
  6. {
  7.     glClearColor(0.1,0.6,0.4,0);
  8.     glMatrixMode(GL_PROJECTION);
  9.     gluOrtho2D(0,700,0,500);
  10.     glMatrixMode(GL_MODELVIEW);
  11. }
  12. void wheel(int x,int y)
  13. {
  14.    float th;
  15.    glBegin(GL_POLYGON);
  16.    glColor3f(0.6,0.4,0.1);
  17.    for(int i=0;i<360;i++)
  18.    {
  19.        th=i*(3.1416/180);
  20.        glVertex2f(x+20*cos(th),y+20*sin(th));
  21.    }
  22.    glEnd();
  23. }
  24. void car()
  25. {
  26.     //Top
  27.    glBegin(GL_POLYGON);
  28.    glVertex2f(150,160);
  29.    glVertex2f(200,220);
  30.    glVertex2f(400,220);
  31.    glVertex2f(450,160);
  32.    glEnd();
  33.  
  34.    //Bottom
  35.    glBegin(GL_POLYGON);
  36.    glVertex2f(100,100);
  37.    glVertex2f(100,160);
  38.    glVertex2f(455,160);
  39.    glVertex2f(455,100);
  40.    glEnd();
  41.  
  42.    wheel(200,100);
  43.    wheel(380,100);
  44. }
  45.  
  46. void display()
  47. {
  48.   glClear(GL_COLOR_BUFFER_BIT);
  49.   glColor3f(0.6,0.1,0.4);
  50.   car();
  51.   glutSwapBuffers();
  52.   glFlush();
  53. }
  54.  
  55. int main(int argc, char **argv)
  56. {
  57.     glutInit(&argc,argv);
  58.     glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE );
  59.     glutInitWindowSize(700,500);
  60.     glutCreateWindow("Sohag Raha - 182-15-2164");
  61.     initOpenGl();
  62.     glutDisplayFunc(display);
  63.     glutMainLoop();
  64.     return 0;
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement