#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 dtTimeStep(void); int main(int argc, char **argv) { // set up window glutInitWindowSize(400, 400); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("Test Harness"); // register callback functions glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); // 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, 3.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.0,0.0,2.0,0.0,0.0,0.0,0.0,1.0,0.0); glTranslatef(0.0f,-0.5f,0.0f); // translate the world down so we aren't // looking at the triangle edge-on // clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // draw a blue triangle with vertices (0,0,0), (0.7,0,0) and (0.7,0,.3) float vertex1[3]={0.0f,0.0f,0.0f}; float vertex2[3]={0.7f,0.0f,0.0f}; float vertex3[3]={0.7f,0.0f,0.3f}; float triangleColor[3]={0.0,0.0,1.0}; // begin triangle draw glColor3f(triangleColor[0], triangleColor[1], triangleColor[2]); glBegin(GL_TRIANGLES); glVertex3f(vertex1[0],vertex1[1],vertex1[2]); glVertex3f(vertex2[0],vertex2[1],vertex2[2]); glVertex3f(vertex3[0],vertex3[1],vertex3[2]); glEnd(); //end triangle draw // draw a red sphere centered at (0.5,0.5,-0.5) with radius .05 float circleCenter[3]={0.5f,0.5f,-0.4f}; float circleRadius=0.05f; float circleColor[3]={1.0f,0.0f,0.0f}; // begin sphere draw glColor3f(circleColor[0],circleColor[1],circleColor[2]); glPushMatrix(); glTranslatef(circleCenter[0],circleCenter[1],circleCenter[2]); // move to center glScalef(circleRadius, circleRadius, circleRadius); //scale radius in x,y, and z glutSolidSphere(1.0f,20,20); // draw a unit square at the origin glPopMatrix(); //end sphere draw // draw to screen glutSwapBuffers(); } void keyboard(unsigned char key, int x, int y) { if (key==' ') dtTimeStep(); } void dtTimeStep() { // enter your code here cout << "You hit the space bar!" << endl; glutPostRedisplay(); }