NAHID_GTC

Untitled

Nov 5th, 2023
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include<windows.h>
  2. #include <GL/glut.h>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. float x = 0.0, y = 100.0;
  7. void init(void)
  8. {
  9.     glClearColor(0.0, 0.0, 0.0, 0.0);
  10.  
  11.     glMatrixMode(GL_PROJECTION);
  12.  
  13.     gluOrtho2D(0.0, 800.0, 0.0, 800.0);
  14. }
  15.  
  16. void drawShapes(void)
  17. {
  18.     glClear(GL_COLOR_BUFFER_BIT);
  19.  
  20.     bool state = false;
  21.  
  22.     if(x <= 700)
  23.     {
  24.         x += 0.1;
  25.     }
  26.     else
  27.     {
  28.         x = 0;
  29.     }
  30.     if(y <= 700)
  31.     {
  32.         y += 0.1;
  33.     }
  34.     else
  35.     {
  36.         y = 0;
  37.     }
  38.     glColor3f(1.0, 1.0, 1.0);
  39.     glBegin(GL_QUADS);
  40.         glVertex2i(x, y);
  41.         glVertex2i(x+100, y);
  42.         glVertex2i(x+100, y-100);
  43.         glVertex2i(x, y-100);
  44.     glEnd();
  45.  
  46.     glColor3f(1.0, 0.0, 0.0);
  47.     glBegin(GL_QUADS);
  48.         glVertex2i(x, 200);
  49.         glVertex2i(x+100, 200);
  50.         glVertex2i(x+100, 100);
  51.         glVertex2i(x, 100);
  52.     glEnd();
  53.  
  54.     glColor3f(0.0, 0.0, 1.0);
  55.     glBegin(GL_QUADS);
  56.         glVertex2i(100, y);
  57.         glVertex2i(200, y);
  58.         glVertex2i(200, y-100);
  59.         glVertex2i(100, y-100);
  60.     glEnd();
  61.  
  62.     glutPostRedisplay();
  63.  
  64. glFlush();
  65.  
  66. }
  67. int main(int argc, char* argv[])
  68. {
  69.  
  70.     glutInit(&argc, argv);
  71.     glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  72.  
  73.     glutInitWindowPosition(1200, 100);
  74.     glutInitWindowSize(900, 900);
  75.     glutCreateWindow("Four Stars");
  76.  
  77.     init();
  78.     glutDisplayFunc(drawShapes);
  79.  
  80.  
  81.     glutMainLoop();
  82.  
  83.     return 0;
  84. }
  85.  
  86.  
  87. /*  cout << x << endl;
  88.     if(!state)
  89.     {
  90.         x += 0.1;
  91.         if(x > 750)
  92.         {
  93.             state != state;
  94.         }
  95.     }
  96.     else
  97.     {
  98.         x -= 0.1;
  99.         if(x <= 1) state != state;
  100.     }
  101. */
  102.  
Advertisement
Add Comment
Please, Sign In to add comment