Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef __APPLE__
- #include <GLUT/glut.h>
- #else
- #include <GL/glut.h>
- #endif
- #include <stdlib.h>
- double rotate_y=0;
- double rotate_x=0;
- int angle = 0;
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glRotatef( rotate_x, 1.0, 0.0, 0.0 );
- glRotatef( rotate_y, 0.0, 1.0, 0.0 );
- glRotatef(180+angle, 0, 0, 1);
- glScalef(0.5f,0.5f,0.5f);
- glLineWidth(4.0);
- glBegin(GL_QUAD_STRIP);
- glColor3f(1.0f,0.0f,1.0f);
- glVertex3i(1,1,0);
- glVertex3i(1,1,-1);
- glVertex3i(0,0,-1);
- glVertex3i(0,0,0);
- glVertex3i(-1,1,0);
- glVertex3i(-1,1,-1);
- glEnd();
- glLoadIdentity();
- glutSwapBuffers();
- }
- void mouse(int button, int state, int x, int y) {
- switch (button) {
- case GLUT_LEFT_BUTTON:
- if (state == GLUT_DOWN)
- exit(0);
- break;
- case GLUT_RIGHT_BUTTON:
- angle += 10;
- break;
- }
- }
- void keyboard(unsigned char key, int x,int y)
- {}
- static void idle(void)
- {
- glutPostRedisplay();
- }
- void keys( int key, int x, int y )
- {
- if(key==GLUT_KEY_RIGHT)
- {
- rotate_y=rotate_y+5;
- }
- if(key==GLUT_KEY_LEFT)
- {
- rotate_y=rotate_y-5;
- }
- if(key==GLUT_KEY_UP)
- {
- rotate_x=rotate_x+5;
- }
- if(key==GLUT_KEY_DOWN)
- {
- rotate_x=rotate_x-5;
- }
- glutPostRedisplay();
- }
- int main(int argc, char *argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(900, 900);
- glutInitWindowPosition (100, 100);
- glutCreateWindow("Assignment 1");
- glutDisplayFunc(display);
- glutMouseFunc(mouse);
- glutKeyboardFunc(keyboard);
- glutSpecialFunc(keys);
- glutIdleFunc(idle);
- glutMainLoop();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment