#include "glut.h" /* global variable declarations */ GLint window1, window2; /* function declarations ----------------------------------*/ void myInit(){ glClearColor(0.0, 0.0, 0.0, 1.0); glColor3f(1.0, 1.0, 1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-1.0, 1.0, -1.0, 1.0); } // end of myInit() /* --------------------------------------------------------*/ void myReshape(int w, int h){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); if ( w <= h ) { // redraw based on shortest side being 2 units gluOrtho2D(-1.0, 1.0, -1.0 * (GLfloat) h / (GLfloat) w, 1.0 * (GLfloat) h / (GLfloat) w); } else { gluOrtho2D(-1.0 * (GLfloat) w / (GLfloat) h, 1.0 * (GLfloat) w / (GLfloat) h, -1.0, 1.0); } glMatrixMode(GL_MODELVIEW); glViewport(0, 0, w, h); } // end of myReshape() /* --------------------------------------------------------*/ void myDisplay1() { GLfloat upleftx = -1.0, uplefty = 1.0, botrightx = 1.0, botrighty = -1.0; glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 0.0, 0.0); glBegin(GL_LINES); glVertex2f(upleftx, uplefty); glVertex2f(botrightx, botrighty); glVertex2f(upleftx, botrighty); glVertex2f(botrightx, uplefty); glEnd(); glBegin(GL_LINE_LOOP); glVertex2f(upleftx, uplefty); glVertex2f(upleftx, botrighty); glVertex2f(botrightx, botrighty); glVertex2f(botrightx, uplefty); glEnd(); glFlush(); } // end of myDisplay1() void myDisplay2() { GLfloat upleftx = -1.0, uplefty = 1.0, botrightx = 1.0, botrighty = -1.0; glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0, 1.0, 1.0); glBegin(GL_LINES); glVertex2f(upleftx, uplefty); glVertex2f(botrightx, botrighty); glVertex2f(upleftx, botrighty); glVertex2f(botrightx, uplefty); glEnd(); glBegin(GL_LINE_LOOP); glVertex2f(upleftx, uplefty); glVertex2f(upleftx, botrighty); glVertex2f(botrightx, botrighty); glVertex2f(botrightx, uplefty); glEnd(); glFlush(); } // end of myDisplay2() /* --------------------------------------------------------*/ int main(int argc, char **argv) { glutInit(&argc, argv); /* set up first window */ glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB ); glutInitWindowSize(200, 200); glutInitWindowPosition(30, 30); window1 = glutCreateWindow("window # 1"); /* register callback functions */ glutDisplayFunc( myDisplay1 ); glutReshapeFunc( myReshape ); /* set up second window */ glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB ); glutInitWindowSize(200, 200); glutInitWindowPosition(300, 30); window2 = glutCreateWindow("window # 2"); /* register callback functions */ glutDisplayFunc( myDisplay2 ); glutReshapeFunc( myReshape ); /* start the event loop */ myInit(); glutMainLoop(); return 0; } // end of main