#include #ifdef _WIN32 #include #endif #ifdef __APPLE__ #include #else #include #endif GLfloat angleInDegrees = 0.f; GLfloat angleSpeed = 50.f; int updatePeriodInMilliseconds = 10; // Initialize OpenGL state void init() { printf("Initializing\n"); glClearColor(0.0, 0.0, 0.0, 1.0); // Also set up the projection matrix if you like. // If you don't, x and y between -1 and 1 will be visible. } // This is called when the window needs to be drawn. // You can force a redraw with glutPostRedisplay() void renderScene() { printf("Window needs rendering\n"); // Clear Color and Depth Buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glLoadIdentity(); glRotatef(angleInDegrees, 0.f, 0.f, 1.f); // Render your scene here, or call functions that render stuff glBegin(GL_TRIANGLES); glVertex3f(-0.5f, 0.f, 0.f); glVertex3f(0.5f, 0.f, 0.f); glVertex3f(0.f, 0.75f, 0.f); glEnd(); glPopMatrix(); glutSwapBuffers(); } // This is called when the window size is changed void changeSize(int w, int h) { printf("window size was changed\n"); } // This is called around 100 times per second void updateScene(int value) { angleInDegrees += angleSpeed * (updatePeriodInMilliseconds * .001); glutTimerFunc(updatePeriodInMilliseconds, updateScene, 0); glutPostRedisplay(); } // This is called when a regular key is pressed void processNormalKeys(unsigned char key, int x, int y) { printf("A normal key was pressed\n"); switch(key) { case '1': printf("One was pressed\n"); break; case 27: printf("Escape was pressed\n"); exit(0); break; default: break; } } // This is called when a special key is pressed (arrows, f3, etc.) void processSpecialKeys(int key, int x, int y) { printf("A special key was pressed\n"); switch(key) { case GLUT_KEY_DOWN: printf("Down was pressed\n"); break; case GLUT_KEY_F1: printf("F1 was pressed\n"); break; default: break; } } int main(int argc, char **argv) { // init GLUT and create window glutInit(&argc, argv); // don't remove this line glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100, 100); glutInitWindowSize(400, 400); glutCreateWindow("GLUT Window"); init(); // Initialize OpenGL state in this // register callbacks // you can remove the ones that you don't need and add other ones here // you do these here once and forget about glut // glut will call them when they are needed glutDisplayFunc(renderScene); glutReshapeFunc(changeSize); glutTimerFunc(updatePeriodInMilliseconds, updateScene, 0); glutKeyboardFunc(processNormalKeys); glutSpecialFunc(processSpecialKeys); // enter GLUT event processing cycle. you no more have control. glut does. glutMainLoop(); return 0; }