Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- #include <cmath>
- #include <ctime>
- GLfloat angle = 0.0f;
- GLfloat speed = 5.0f;
- GLfloat r = 0.0f;
- GLfloat g = 0.0f;
- GLfloat b = 0.0f;
- #define PI 3.14159265358979323846264338327950288419716939937510
- int points = 3;
- int timer = 25;
- static int window;
- void renderScene(void)
- {
- if (points >= 3 && points <= 8)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glRotatef(angle, 0, 0, 1);
- glBegin(GL_TRIANGLES);
- GLfloat temp = (2 * PI) / points;
- for (size_t i = 0; i < points; i++)
- {
- glColor3f(r, g, b);
- glVertex3f(0.0f, 0.0f, 0.0f);
- glColor3f(r, g, b);
- glVertex3f(cos(i * temp), sin(i * temp), 0.0f);
- glColor3f(r, g, b);
- glVertex3f(cos((i + 1) * temp), sin((i + 1) * temp), 0.0f);
- }
- glEnd();
- glutSwapBuffers();
- }
- }
- void timerCallback(int)
- {
- angle += speed;
- glutTimerFunc(timer, timerCallback, 0);
- renderScene();
- }
- void colorCallback(int)
- {
- r = (rand() % 100) / 100.0f;
- g = (rand() % 100) / 100.0f;
- b = (rand() % 100) / 100.0f;
- glutTimerFunc(2000, colorCallback, 0);
- }
- void kbCallback(unsigned char key, int, int)
- {
- speed = -speed;
- }
- void menuCallback(int entry)
- {
- if (entry == 1)
- {
- glutDestroyWindow(window);
- exit(0);
- }
- else points = entry;
- }
- int main(int argc, char** argv)
- {
- srand(time(NULL));
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
- glutInitWindowPosition(100, 100);
- glutInitWindowSize(320, 320);
- window = glutCreateWindow("WOOOT");
- glutDisplayFunc(renderScene);
- glutTimerFunc(timer, timerCallback, 0);
- glutTimerFunc(2000, colorCallback, 0);
- glutKeyboardFunc(kbCallback);
- glutCreateMenu(menuCallback);
- glutAddMenuEntry("EXIT", 1);
- glutAddMenuEntry("3", 3);
- glutAddMenuEntry("4", 4);
- glutAddMenuEntry("5", 5);
- glutAddMenuEntry("6", 6);
- glutAddMenuEntry("7", 7);
- glutAddMenuEntry("8", 8);
- glutAttachMenu(GLUT_LEFT_BUTTON);
- glutMainLoop();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement