// // OpenGL program to draw the XYZ axes of the world frame, and // a scaled wireframe cube positioned at the origin of the world frame. // #include void init() { glClearColor(0.0, 0.0, 0.0, 0.0); // background color } // callback function when window is reshaped void reshape(int w, int h) { glViewport(0, 0, w, h); // w and h are passed by GLUT glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Perspective projection: fov (in y), aspect ratio, near, far gluPerspective(60.0, (float) w/h, 1.0, 20.0); // Orthographic projection: left, right, bottom, top, near, far // glOrtho(-2.0, 2.0, -2.0, 2.0, 1.0, 20.0); glMatrixMode(GL_MODELVIEW); } // all routines to redraw scene void display() { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); // viewing transformation, sets camera position, aim by specifying // eye coords, center coords, and up vector gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); // draw world coordinate axes (useful for debugging) glLineWidth(2.0); glBegin(GL_LINES); // X axis, red glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(1.0, 0.0, 0.0); // Y axis, green glColor3f(0.0, 1.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); // Z axis, blue glColor3f(0.0, 0.0, 1.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 1.0); glEnd(); glLineWidth(1.0); glColor3f(1.0, 1.0, 1.0); glScalef(1.0, 3.0, 1.0); // scale cube by 3.0 along Y axis glutWireCube(1.0); // draw wireframe cube glFlush(); } // input keyboard function to quit with q or Q. void keyboard(unsigned char key, int x, int y) { if (key == 'q' || key == 'Q') exit(0); } int main (int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowSize(400,400); // width, height in pixels glutInitWindowPosition(400,0); // x, y from top left corner of screen glutCreateWindow(argv[0]); // program name is window title init(); // register the callback functions glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutDisplayFunc(display); glutMainLoop(); return 0; }