Advertisement
shoroujjahan

Untitled

Aug 2nd, 2021
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GL/gl.h>
  2. #include <GL/glut.h>
  3. #include <math.h>
  4.  
  5. void drawFilledCircle(GLfloat x, GLfloat y, GLfloat radius)
  6.  {
  7.      int i;
  8.      int triangleAmount = 50;
  9.      GLfloat twicePi = 2.0f * 3.1416;
  10.  
  11.  
  12.      glBegin(GL_TRIANGLE_FAN);
  13.         glVertex2f(x, y);
  14.         for(i = 0; i <= triangleAmount; i++) {
  15.                 glVertex2f(x + (radius * cos(i * twicePi / triangleAmount)), y + (radius * sin(i * twicePi/ triangleAmount)));
  16.         }
  17.      glEnd();
  18.  
  19.  
  20.  
  21.  
  22.  }
  23.  
  24. void display(void)
  25. {
  26. /*  clear all pixels  */
  27.     glClear (GL_COLOR_BUFFER_BIT);
  28.  
  29. /*  draw white polygon (rectangle) with corners at
  30.  *  (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
  31.  */
  32.  
  33.  glColor3f(0.0f, 0.5f, 1.0f);//baby Blue Sky
  34.     glBegin(GL_POLYGON);
  35.         glVertex3f (00, 50, 0.0);
  36.         glVertex3f (100, 50, 0.0);
  37.         glVertex3f (100, 100, 0.0);
  38.         glVertex3f (00, 100, 0.0);
  39.     glEnd();
  40.  
  41.    glColor3f(0.1f, 0.8f, 0.3f);//Ground
  42.     glBegin(GL_POLYGON);
  43.         glVertex3f (00, 00, 0.0);
  44.         glVertex3f (100, 00, 0.0);
  45.         glVertex3f (100, 50, 0.0);
  46.         glVertex3f (00, 50, 0.0);
  47.     glEnd();
  48.  
  49.     glColor3f(0.1f, 0.1f, 0.1f);//Dark grey//Road
  50.     glBegin(GL_POLYGON);
  51.         glVertex3f (0, 25, 0.0);
  52.         glVertex3f (100, 25, 0.0);
  53.         glVertex3f (100, 38, 0.0);
  54.         glVertex3f (0, 38, 0.0);
  55.     glEnd();
  56.  
  57.  
  58.  
  59.     glColor3f(0.3f, 0.3f, 0.4f);//Violet(House1)
  60.     glBegin(GL_POLYGON);
  61.         glVertex3f (22, 40, 0.0);
  62.         glVertex3f (32, 40, 0.0);
  63.         glVertex3f (32, 67, 0.0);
  64.         glVertex3f (22, 67, 0.0);
  65.     glEnd();
  66.  
  67.     glColor3f(0.3f, 0.3f, 0.5f);
  68.         glBegin(GL_POLYGON);
  69.         glVertex3f (32, 40, 0.0);
  70.         glVertex3f (33, 40, 0.0);
  71.         glVertex3f (33, 65, 0.0);
  72.         glVertex3f (32, 67, 0.0);
  73.     glEnd();
  74.  
  75.  
  76.  
  77.             glColor3f(0.0f, 0.1f, 0.2f);//Windows
  78.             glBegin(GL_POLYGON);
  79.                 glVertex3f (23, 48, 0.0);
  80.                 glVertex3f (24.5, 48, 0.0);
  81.                 glVertex3f (24.5, 50, 0.0);
  82.                 glVertex3f (23, 50, 0.0);
  83.             glEnd();
  84.  
  85.             glBegin(GL_POLYGON);
  86.                 glVertex3f (26, 48, 0.0);
  87.                 glVertex3f (27.5, 48, 0.0);
  88.                 glVertex3f (27.5, 50, 0.0);
  89.                 glVertex3f (26, 50, 0.0);
  90.             glEnd();
  91.  
  92.             glBegin(GL_POLYGON);
  93.                 glVertex3f (29, 48, 0.0);
  94.                 glVertex3f (30.5, 48, 0.0);
  95.                 glVertex3f (30.5, 50, 0.0);
  96.                 glVertex3f (29, 50, 0.0);
  97.             glEnd();
  98.  
  99.             glBegin(GL_POLYGON);
  100.                 glVertex3f (23, 54, 0.0);
  101.                 glVertex3f (24.5, 54, 0.0);
  102.                 glVertex3f (24.5, 56, 0.0);
  103.                 glVertex3f (23, 56, 0.0);
  104.             glEnd();
  105.  
  106.             glBegin(GL_POLYGON);
  107.                 glVertex3f (26, 54, 0.0);
  108.                 glVertex3f (27.5, 54, 0.0);
  109.                 glVertex3f (27.5, 56, 0.0);
  110.                 glVertex3f (26, 56, 0.0);
  111.             glEnd();
  112.  
  113.              glBegin(GL_POLYGON);
  114.                 glVertex3f (29, 54, 0.0);
  115.                 glVertex3f (30.5, 54, 0.0);
  116.                 glVertex3f (30.5, 56, 0.0);
  117.                 glVertex3f (29, 56, 0.0);
  118.             glEnd();
  119.  
  120.               glBegin(GL_POLYGON);
  121.                 glVertex3f (29, 60, 0.0);
  122.                 glVertex3f (30.5, 60, 0.0);
  123.                 glVertex3f (30.5, 62, 0.0);
  124.                 glVertex3f (29, 62, 0.0);
  125.             glEnd();
  126.  
  127.             glBegin(GL_POLYGON);
  128.                 glVertex3f (26, 60, 0.0);
  129.                 glVertex3f (27.5, 60, 0.0);
  130.                 glVertex3f (27.5, 62, 0.0);
  131.                 glVertex3f (26, 62, 0.0);
  132.             glEnd();
  133.  
  134.              glBegin(GL_POLYGON);
  135.                 glVertex3f (23, 60, 0.0);
  136.                 glVertex3f (24.5, 60, 0.0);
  137.                 glVertex3f (24.5, 62, 0.0);
  138.                 glVertex3f (23, 62, 0.0);
  139.             glEnd();
  140.  
  141.  
  142.                     glColor3f(0.2f, 0.2f, 0.1f);//Violet(House2)
  143.                         glBegin(GL_POLYGON);
  144.                         glVertex3f (52, 40, 0.0);
  145.                         glVertex3f (62, 40, 0.0);
  146.                         glVertex3f (62, 62, 0.0);
  147.                         glVertex3f (52, 62, 0.0);
  148.                         glEnd();
  149.  
  150.                          glColor3f(0.3f, 0.2f, 0.1f);
  151.                         glBegin(GL_POLYGON);
  152.                         glVertex3f (62, 40, 0.0);
  153.                         glVertex3f (63, 40, 0.0);
  154.                         glVertex3f (63, 61, 0.0);
  155.                         glVertex3f (62, 62, 0.0);
  156.                         glEnd();
  157.  
  158.              glColor3f(0.0f, 0.0f, 0.0f);//Windows
  159.             glBegin(GL_POLYGON);
  160.                 glVertex3f (53.5, 48, 0.0);
  161.                 glVertex3f (56, 48, 0.0);
  162.                 glVertex3f (56, 51, 0.0);
  163.                 glVertex3f (53.5, 51, 0.0);
  164.             glEnd();
  165.  
  166.             glBegin(GL_POLYGON);
  167.                 glVertex3f (58, 48, 0.0);
  168.                 glVertex3f (60.5, 48, 0.0);
  169.                 glVertex3f (60.5, 51, 0.0);
  170.                 glVertex3f (58, 51, 0.0);
  171.             glEnd();
  172.  
  173.              glBegin(GL_POLYGON);
  174.                 glVertex3f (53.5, 54, 0.0);
  175.                 glVertex3f (56, 54, 0.0);
  176.                 glVertex3f (56, 57, 0.0);
  177.                 glVertex3f (53.5, 57, 0.0);
  178.             glEnd();
  179.  
  180.             glBegin(GL_POLYGON);
  181.                 glVertex3f (58, 54, 0.0);
  182.                 glVertex3f (60.5, 54, 0.0);
  183.                 glVertex3f (60.5, 57, 0.0);
  184.                 glVertex3f (58, 57, 0.0);
  185.             glEnd();
  186.  
  187.     glColor4f(1.0f, 0.0f, 0.0f, 0.0f);//red//for car
  188.             glBegin(GL_POLYGON);
  189.                 glVertex3f (38, 29.5, 0.0);
  190.                 glVertex3f (50, 29.5, 0.0);
  191.                 glVertex3f (50, 33, 0.0);
  192.                 glVertex3f (38, 33, 0.0);
  193.             glEnd();
  194.             glBegin(GL_POLYGON);
  195.                 glVertex3f (39.5, 33, 0.0);
  196.                 glVertex3f (50, 33, 0.0);
  197.                 glVertex3f (48, 36, 0.0);
  198.                 glVertex3f (42, 36, 0.0);
  199.             glEnd();
  200.  
  201.             glColor3f (0.0,0.0,0.0);
  202.            glBegin(GL_POLYGON);
  203.                 glVertex3f (39.5, 33.1, 0.0);
  204.                 glVertex3f (50, 33.1, 0.0);
  205.                 glVertex3f (50, 33, 0.0);
  206.                 glVertex3f (39.5, 33, 0.0);
  207.             glEnd();
  208.  
  209.             glBegin(GL_POLYGON);
  210.                 glVertex3f (45, 29.5, 0.0);
  211.                 glVertex3f (45.1, 29.5, 0.0);
  212.                 glVertex3f (45.1, 36, 0.0);
  213.                 glVertex3f (45, 36, 0.0);
  214.             glEnd();
  215.  
  216.              glBegin(GL_POLYGON);
  217.                 glVertex3f (48, 33, 0.0);
  218.                 glVertex3f (48.1, 33, 0.0);
  219.                 glVertex3f (48.1, 36, 0.0);
  220.                 glVertex3f (48, 36, 0.0);
  221.             glEnd();
  222.             glBegin(GL_POLYGON);
  223.                 glVertex3f (42, 33, 0.0);
  224.                 glVertex3f (42.1, 33, 0.0);
  225.                 glVertex3f (42.1, 36, 0.0);
  226.                 glVertex3f (42, 36, 0.0);
  227.             glEnd();
  228.  
  229.  
  230.  
  231. /*  don't wait!
  232.  *  start processing buffered OpenGL routines
  233.  */
  234.    glFlush ();
  235.     //For Sun
  236.      glColor3f (.87,0.88,.1);
  237.      drawFilledCircle(80,80,3);
  238.      //For car1 wheel
  239.      glColor3f (0.0,0.0,0.0);
  240.      drawFilledCircle(41,29.5,1.1);
  241.  
  242.      glColor3f(0.1f, 0.1f, 0.0f);//Bronze
  243.      drawFilledCircle(41,29.5,0.5);
  244.  
  245.  
  246. //For car1 wheel2
  247.      glColor3f (0.0,0.0,0.0);
  248.      drawFilledCircle(47,29.5,1.1);
  249.  
  250.      glColor3f(0.1f, 0.1f, 0.0f);//Bronze
  251.      drawFilledCircle(47,29.5,0.5);
  252.  
  253.      glFlush();
  254. }
  255.  
  256. void init (void)
  257. {
  258. /*  select clearing (background) color       */
  259.     glClearColor (0.0, 0.0, 0.0, 0.0);
  260.  
  261. /*  initialize viewing values  */
  262.     glMatrixMode(GL_PROJECTION);
  263.     glLoadIdentity();
  264.     glOrtho(0.0, 100, 0.0, 100, -1.0, 1.0);
  265. }
  266.  
  267. /*
  268.  *  Declare initial window size, position, and display mode
  269.  *  (single buffer and RGBA).  Open window with "hello"
  270.  *  in its title bar.  Call initialization routines.
  271.  *  Register callback function to display graphics.
  272.  *  Enter main loop and process events.
  273.  */
  274. int main(int argc, char** argv)
  275. {
  276.     glutInit(&argc, argv);
  277.     glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  278.     glutInitWindowSize (1300, 1000);
  279.     glutInitWindowPosition (75,75);
  280.     glutCreateWindow ("Fist Lab Task");
  281.     init ();
  282.     glutDisplayFunc(display);
  283.     glutMainLoop();
  284.     return 0;   /* ISO C requires main to return int. */
  285. }
  286.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement