Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <GL/glut.h>
  2. #include <cmath>
  3. #include <ctime>
  4.  
  5. GLfloat angle = 0.0f;
  6. GLfloat speed = 5.0f;
  7.  
  8. GLfloat r = 0.0f;
  9. GLfloat g = 0.0f;
  10. GLfloat b = 0.0f;
  11.  
  12. #define PI 3.14159265358979323846264338327950288419716939937510
  13.  
  14. int points = 3;
  15. int timer = 25;
  16. static int window;
  17.  
  18. void renderScene(void)
  19. {
  20. if (points >= 3 && points <= 8)
  21. {
  22. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  23.  
  24. glLoadIdentity();
  25. glRotatef(angle, 0, 0, 1);
  26.  
  27. glBegin(GL_TRIANGLES);
  28.  
  29. GLfloat temp = (2 * PI) / points;
  30.  
  31. for (size_t i = 0; i < points; i++)
  32. {
  33. glColor3f(r, g, b);
  34. glVertex3f(0.0f, 0.0f, 0.0f);
  35.  
  36. glColor3f(r, g, b);
  37. glVertex3f(cos(i * temp), sin(i * temp), 0.0f);
  38.  
  39. glColor3f(r, g, b);
  40. glVertex3f(cos((i + 1) * temp), sin((i + 1) * temp), 0.0f);
  41. }
  42.  
  43. glEnd();
  44.  
  45. glutSwapBuffers();
  46. }
  47. }
  48.  
  49. void timerCallback(int)
  50. {
  51. angle += speed;
  52. glutTimerFunc(timer, timerCallback, 0);
  53. renderScene();
  54. }
  55.  
  56. void colorCallback(int)
  57. {
  58. r = (rand() % 100) / 100.0f;
  59. g = (rand() % 100) / 100.0f;
  60. b = (rand() % 100) / 100.0f;
  61.  
  62. glutTimerFunc(2000, colorCallback, 0);
  63. }
  64.  
  65. void kbCallback(unsigned char key, int, int)
  66. {
  67. speed = -speed;
  68. }
  69.  
  70. void menuCallback(int entry)
  71. {
  72. if (entry == 1)
  73. {
  74. glutDestroyWindow(window);
  75. exit(0);
  76. }
  77. else points = entry;
  78. }
  79.  
  80. int main(int argc, char** argv)
  81. {
  82. srand(time(NULL));
  83.  
  84. glutInit(&argc, argv);
  85. glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  86. glutInitWindowPosition(100, 100);
  87. glutInitWindowSize(320, 320);
  88. window = glutCreateWindow("WOOOT");
  89.  
  90. glutDisplayFunc(renderScene);
  91. glutTimerFunc(timer, timerCallback, 0);
  92. glutTimerFunc(2000, colorCallback, 0);
  93. glutKeyboardFunc(kbCallback);
  94.  
  95. glutCreateMenu(menuCallback);
  96. glutAddMenuEntry("EXIT", 1);
  97. glutAddMenuEntry("3", 3);
  98. glutAddMenuEntry("4", 4);
  99. glutAddMenuEntry("5", 5);
  100. glutAddMenuEntry("6", 6);
  101. glutAddMenuEntry("7", 7);
  102. glutAddMenuEntry("8", 8);
  103.  
  104. glutAttachMenu(GLUT_LEFT_BUTTON);
  105.  
  106. glutMainLoop();
  107.  
  108. return 1;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement