// An rudimentary example program as a starting point for your 1st assignment // Simply draw some interesting figure of your own design and email me the // source code ---- NO BINARIES PLEASE! #include #include #include #include #include // In OS X change to #include #define WINDOW_HEIGHT 500 #define WINDOW_WIDTH 500 // Parameters float WinX = 0, WinY = 0; static void Draw(void) { // How often is this called on your machine? glClear(GL_COLOR_BUFFER_BIT); // What happens if we don't do this? // Draw some innovative figure here after the clear but before flush. glBegin(GL_LINES); glVertex2f(0, 0); glVertex2f(WinX, WinY); glEnd(); glFlush(); glutReportErrors(); glutPostRedisplay(); } static void Reshape(int width, int height) { // Called when window resized int viewport_width = WinX = width; int viewport_height = WinY = height; glViewport(0, 0, viewport_width, viewport_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, viewport_width, 0, viewport_height, 1, 10); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0, 0, 7, 0, 0, 0, 0, 1, 0); glClear(GL_COLOR_BUFFER_BIT); } void Initialize(int argc, char **argv) { glutInit(&argc, argv); // Initialize GLUT Window. glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); glutCreateWindow("Example Line"); // Assign Callback functions for reshape event and display events. glutReshapeFunc(Reshape); glutDisplayFunc(Draw); // Initialize OpenGL parameters to desired states. glClearColor(0.0, 0.0, 1.0, 1); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); } int main(int argc, char **argv) { Initialize(argc, argv); glutReportErrors(); // Tell Glut to report any errors that occured. glutMainLoop(); // Begin main program loop return(0); // This will not be reached }