#include #include // function prototypes void display(void); void reshape(int width, int height); void keyboard(unsigned char key, int x, int y); void init(void); void mouse(int button, int state, int x, int y); void motion(int x, int y); int windowWidth = 400; int windowHeight = 400; int main(int argc, char **argv) { // set up window glutInitWindowSize(windowWidth, windowHeight); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("Test Harness"); // register callback functions glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMouseFunc(mouse); glutMotionFunc(motion); // initalize opengl parameters init(); // loop until something happens glutMainLoop(); return 0; } void init() { // initialize viewing system glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, 1.0, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); // initialize background color to black glClearColor(0.0,0.0,0.0,0.0); // enable depth buffering glEnable(GL_DEPTH_TEST); } void reshape(int width, int height) { glViewport(0,0,width,height); } void display() { // initialize modelview matrix glLoadIdentity(); gluLookAt(0,1,5,0,1,0,0,1,0); // clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // draw a blue triangle with vertices (0,0,0), (1,0,0), (0.5f,0,0.5f) glColor3f(0,0,1); // establish color glBegin(GL_TRIANGLES); glVertex3f(0,0,0); glVertex3f(1,0,0); glVertex3f(0.5f,0,0.5f); glEnd(); // draw a red sphere centered at (0.5,0.5,-0.5) with radius .05 glColor3f(1,0,0); // establish color in RGB glPushMatrix(); glTranslatef(0.5f,0.5f,-0.5f); // move center glutSolidSphere(0.05f,20,20); // draw a unit sphere at the origin glPopMatrix(); //end sphere draw // draw to screen glutSwapBuffers(); } void keyboard(unsigned char key, int x, int y) { if (key==' ') cout << "You hit the space bar." << endl; glutPostRedisplay(); // redraw screen when all other requests // are satisfied } void mouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) cout << "You pressed the left mouse button down." << endl; glutPostRedisplay(); // redraw screen when all other requests // are satisfied } void motion(int x, int y) { cout << "You moved the mouse to " << x << " " << y << endl; glutPostRedisplay(); // redraw screen when all other requests // are satisfied }