#include #include #include #include #include #include #define DTOR 0.0174532925 #define CROSSPROD(p1,p2,p3) \ p3.x = p1.y*p2.z - p1.z*p2.y; \ p3.y = p1.z*p2.x - p1.x*p2.z; \ p3.z = p1.x*p2.y - p1.y*p2.x #ifndef MIN #define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif int gMainWindow = 0; int screenWidth = 600; int screenHeight = 600; int rColor = 1.0; int gColor = 1.0; int bColor = 1.0; float angle = 0.0; int spin = 0; #pragma mark ---- GLUT callbacks ---- void init (void) { glClearColor(0.0, 0.0,0.0, 0.0); } void reshape (int w, int h) { glViewport(0, 0, (GLuint) w,(GLuint) h); glutPostRedisplay(); // glClearColor(((double) w/screenWidth) * 0.5,((double) w/screenWidth) * 0.5,((double) w/screenWidth) * 0.5, 1.0); } void maindisplay(void) { // glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(rColor, gColor, bColor); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glRotatef(angle, 0.0, 0.0, 1.0); glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); // glFinish(); glutSwapBuffers(); } void special(int key, int px, int py) { } void mouse (int button, int state, int x, int y) { } void key(unsigned char inkey, int px, int py) { switch (inkey) { case 'r': if (rColor > 0.5) rColor = 0.0; else rColor = 1.0; break; case 's': if (spin == 0) spin = 1; else spin = 0; break; default: break; } glutPostRedisplay(); } void timer(int temp) { if (spin) { angle += 0.1; if (angle > 360.0) angle = angle - 360.0; glutPostRedisplay(); } glutTimerFunc(100, timer, 0); } #pragma mark ---- main ---- int main (int argc, const char * argv[]) { glutInit(&argc, (char **)argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); // non-stereo for main window glutInitWindowPosition (300, 50); glutInitWindowSize (screenWidth, screenHeight); gMainWindow = glutCreateWindow("GLUT Basics"); init(); // standard GL init glutReshapeFunc (reshape); glutDisplayFunc (maindisplay); glutKeyboardFunc (key); // glutSpecialFunc (special); // glutMouseFunc (mouse); // glutIdleFunc(idle); glutTimerFunc(100, timer, 0); glutMainLoop(); return 0; }