imtiazaasif

Moving boat using openGl

Jun 9th, 2022 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. //#include<windows.h>
  2. #ifdef __APPLE__
  3. #include <GLUT/glut.h>
  4. #else
  5. #include <GL/glut.h>
  6. #endif
  7.  
  8. #include <stdlib.h>
  9.  
  10. #include <math.h>
  11.  
  12. float p = -10.0; // Display Measurement with ortho starting from the left -10 and right 10
  13.  
  14. void display(void)
  15. {
  16.   glClear(GL_COLOR_BUFFER_BIT);
  17.  
  18.   if (p <= 10)    // moving limit with the display measurement
  19.     p = p + .003; // changing the object position for redisplaying
  20.  
  21.   else
  22.     p = -10; // For backing the object continuously
  23.  
  24.   glutPostRedisplay(); // To redraw the object in the display
  25.  
  26.   glBegin(GL_QUADS);
  27.   glColor3f(1.0, 0.0, 1.0);
  28.   glVertex2f(p + 1, -8); // a     // boat
  29.   glVertex2f(p + 6, -8); // b
  30.   glVertex2f(p + 5, -9); // c
  31.   glVertex2f(p + 2, -9); // d
  32.  
  33.   glColor3f(0.0, 1.0, 1.0);
  34.   glVertex2f(p + 4, -5); // a     // khamba
  35.   glVertex2f(p + 5, -5); // b
  36.   glVertex2f(p + 5, -8); // c
  37.   glVertex2f(p + 4, -8); // d
  38.  
  39.   glColor3f(1.0, 1.0, 0.0);
  40.   glVertex2f(p + 3, -6); // a     // flag
  41.   glVertex2f(p + 4, -5); // b
  42.   glVertex2f(p + 4, -7); // c
  43.   glVertex2f(p + 3, -6); // a
  44.  
  45.   glEnd();
  46.  
  47.   glFlush();
  48. }
  49. void init(void)
  50. {
  51.   glClearColor(1.0, 0.0, 0.0, 0.0);   // Background Color
  52.   glOrtho(-10, 10, -10, 10, -10, 10); // To specify the coordinate & Specify the distances to the nearer and farther depth clipping planes.
  53. }
  54.  
  55. int main(int argc, char **argv)
  56. {
  57.   glutInit(&argc, argv);
  58.   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // Single Frame
  59.   glutInitWindowSize(600, 600);
  60.   glutInitWindowPosition(100, 100);
  61.   glutCreateWindow("moving_object");
  62.   init(); // Set up constants with default values
  63.   glutDisplayFunc(display);
  64.   glutMainLoop(); // It enters the GLUT event processing loop.should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered.
  65.   return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment