From: Ash Tyndall Date: Sun, 9 Oct 2011 06:45:10 +0000 (+0800) Subject: (no commit message) X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=commitdiff_plain;h=bfb8cab4390e0707a66fa2cdf10ff41d274ebd62 --- diff --git a/scene.c b/scene.c index e7becbf..f899dd8 100644 --- a/scene.c +++ b/scene.c @@ -464,15 +464,14 @@ void makeMenu() { * @param h New height */ void windowReshape(int w, int h) { - glViewport(0, 0, w, h); // Reset The Current Viewport - glMatrixMode(GL_PROJECTION); // Select The Projection Matrix - glLoadIdentity(); // Reset The Projection Matrix - - // Calculate The Aspect Ratio Of The Window - gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f); - - glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix - glLoadIdentity(); // Reset The Modelview Matrix + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); /* switch matrix mode */ + glLoadIdentity(); + if (w <= h) + gluOrtho2D(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w, 2.0 * (GLfloat) h / (GLfloat) w); + else + gluOrtho2D(-2.0 * (GLfloat) w / (GLfloat) h, 2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0); + glMatrixMode(GL_MODELVIEW); /* return to modelview mode */ } /** @@ -496,7 +495,7 @@ void display() { glTranslatef(-1.5f, 0.0f, -6.0f); glBegin(GL_QUADS); - glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red + glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red glVertex3f(-1.0f, 1.0f, 0.0f); // Top left glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right @@ -539,8 +538,6 @@ int main(int argc, char **argv) { glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations - glutSwapBuffers(); - glutReshapeFunc(windowReshape); glutDisplayFunc(display); glutMouseFunc(mouse);